Skip to content
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

fix(common): support density descriptors with 2+ decimals #47197

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -32,9 +32,9 @@ const VALID_WIDTH_DESCRIPTOR_SRCSET = /^((\s*\d+w\s*(,|$)){1,})$/;

/**
* RegExpr to determine whether a src in a srcset is using density descriptors.
* Should match something like: "1x, 2x".
* Should match something like: "1x, 2x". Also supports decimals like "1.5x".
*/
const VALID_DENSITY_DESCRIPTOR_SRCSET = /^((\s*\d(\.\d)?x\s*(,|$)){1,})$/;
const VALID_DENSITY_DESCRIPTOR_SRCSET = /^((\s*\d(\.\d+)?x\s*(,|$)){1,})$/;

/**
* Srcset values with a density descriptor higher than this value will actively
Expand Down
4 changes: 2 additions & 2 deletions packages/common/test/directives/ng_optimized_image_spec.ts
Expand Up @@ -966,7 +966,7 @@ describe('Image directive', () => {
setupTestingModule({imageLoader});

const template = `
<img rawSrc="img.png" rawSrcset="1x, 2.5x, 3x" width="100" height="50">
<img rawSrc="img.png" rawSrcset="1.75x, 2.5x, 3x" width="100" height="50">
`;
const fixture = createTestComponent(template);
fixture.detectChanges();
Expand All @@ -976,7 +976,7 @@ describe('Image directive', () => {
expect(img.src).toBe(`${IMG_BASE_URL}/img.png`);
expect(img.srcset)
.toBe(
`${IMG_BASE_URL}/img.png?w=100 1x, ` +
`${IMG_BASE_URL}/img.png?w=175 1.75x, ` +
`${IMG_BASE_URL}/img.png?w=250 2.5x, ` +
`${IMG_BASE_URL}/img.png?w=300 3x`);
});
Expand Down