-
Notifications
You must be signed in to change notification settings - Fork 30
Add product Element #14454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add product Element #14454
Conversation
- minor tweaks to left col card so its more aligned with the figma - removed retailer from the price row (TBC) - reworded cta (this TBC) - updated storybooks to reflect the likes/dislikes of product
- removed retailer from the price row (TBC) - reworded cta (this TBC) - updated storybook to reflect the likes/dislikes of product - added url cleaner
<div css={productInfoContainer}>{children}</div> | ||
); | ||
|
||
const stripHtml = (html: string) => html.replace(/<[^>]+>/g, ''); |
Check failure
Code scanning / CodeQL
Incomplete multi-character sanitization High
<script
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 2 days ago
General fix approach:
The best way to fix the incomplete multi-character sanitization problem is to use a well-tested library like sanitize-html
to strip out HTML tags correctly, as hand-rolled regex-based HTML removal is error-prone and inherently incomplete.
Detailed fix for this code:
- Replace the current
stripHtml
implementation with a call tosanitize-html
, configured to remove all HTML tags and escape content. - Add an import for
sanitize-html
at the top. - Optionally, if external libraries are undesirable, repeatedly apply the regular expression replacement in a loop until the string no longer changes (but this is discouraged in favor of a library).
- No other parts of the file need to change.
Specific changes to apply:
- Add
import sanitizeHtml from 'sanitize-html';
at the top of the file. - Replace the implementation of
stripHtml
with a function that callssanitizeHtml(html, { allowedTags: [], allowedAttributes: {} })
, which removes all HTML tags.
-
Copy modified line R2 -
Copy modified line R105
@@ -1,4 +1,5 @@ | ||
import { css } from '@emotion/react'; | ||
import sanitizeHtml from 'sanitize-html'; | ||
import { | ||
from, | ||
headlineMedium20, | ||
@@ -101,7 +102,7 @@ | ||
<div css={productInfoContainer}>{children}</div> | ||
); | ||
|
||
const stripHtml = (html: string) => html.replace(/<[^>]+>/g, ''); | ||
const stripHtml = (html: string) => sanitizeHtml(html, { allowedTags: [], allowedAttributes: {} }); | ||
|
||
export const InlineProductCard = ({ | ||
format, |
<div css={productInfoContainer}>{children}</div> | ||
); | ||
|
||
const stripHtml = (html: string) => html.replace(/<[^>]+>/g, ''); |
Check failure
Code scanning / CodeQL
Polynomial regular expression used on uncontrolled data High
regular expression
a user-provided value
This
regular expression
a user-provided value
This
regular expression
a user-provided value
This
co-authored by @charleycampbell
What does this change?
We're introducing two new product card components,
InlineProductCard
andLeftColProductCard
, along with supporting changes to styling, image handling, and schema updates.These components are designed to display product information inline and in the left column of articles, with different layouts and palette colours. The changes also include updates to the image sizing logic for product cards and enhancements to the button styling for product links.
New Product Card Components:
InlineProductCard
andLeftColProductCard
components to display product information, including brand, product name, image, pricing, retailer links, CTAs, and statistics. Each component has its own layout and styling for different breakpoints.Styling and Palette Enhancements:
Image Handling:
Picture
component to support a newproductCard
role type, with tailored image sizing logic for product cards at different breakpoints.Schema Updates:
elementId
forLinkBlockElement
, ensuring unique identification and improved data integrity for product-related links. This was already coming from FE but was missing from the model in DCR. This is a fix and allows us to directly copy elements from FE forProductElement.stories.tsx
Why?
We are adding in a new element called
Product
. This product element will help structure the product data and also the ability to display product reviews as part of the new designs. This is the RFCScreenshots
LeftCol product card
