Skip to content

Commit

Permalink
allow ssr-css query param for parseExtensionUrl (#38394)
Browse files Browse the repository at this point in the history
  • Loading branch information
erwinmombay committed Aug 9, 2022
1 parent beb9a33 commit 5147b5f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/service/extension-script.js
Expand Up @@ -105,7 +105,7 @@ export function parseExtensionUrl(scriptUrl) {
}
// Note that the "(\.max)?" group only applies to local dev.
const matches = scriptUrl.match(
/^(.*)\/(.*)-([0-9.]+|latest)(\.max)?\.(?:js|mjs)$/i
/^(.*)\/(.*)-([0-9.]+|latest)(\.max)?\.(?:js|mjs)(?:\?ssr-css=[0|1])?$/i
);
const extensionId = matches ? matches[2] : undefined;
const extensionVersion = matches ? matches[3] : undefined;
Expand Down
25 changes: 25 additions & 0 deletions test/unit/test-extension-script.js
Expand Up @@ -411,6 +411,22 @@ describes.fakeWin('getExtensionScripts', {}, (env) => {
})
);

doc.head.appendChild(
createElementWithAttributes(doc, 'script', {
'id': 'amp-ext3-with-ssr-css-query-param-on',
'custom-element': 'amp-ext3',
'src': 'https://cdn.ampproject.org/v0/amp-ext3-0.3.js?ssr-css=1',
})
);

doc.head.appendChild(
createElementWithAttributes(doc, 'script', {
'id': 'amp-ext3-with-ssr-css-query-param-off',
'custom-element': 'amp-ext3',
'src': 'https://cdn.ampproject.org/v0/amp-ext3-0.3.js?ssr-css=0',
})
);

doc.head.appendChild(
createElementWithAttributes(doc, 'script', {
'id': 'amp-ext2-latest',
Expand Down Expand Up @@ -455,6 +471,15 @@ describes.fakeWin('getExtensionScripts', {}, (env) => {
).to.deep.equal(['amp-ext2-latest']);
});

it('should find a specific version with ssr-css query param', () => {
expect(
ids(getExtensionScripts(win, 'amp-ext3', '0.3', true))
).to.deep.equal([
'amp-ext3-with-ssr-css-query-param-on',
'amp-ext3-with-ssr-css-query-param-off',
]);
});

it('should find an intermediate extension', () => {
expect(
ids(getExtensionScripts(win, '_intermediate', '', false))
Expand Down

0 comments on commit 5147b5f

Please sign in to comment.