Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions extensions/amp-a4a/0.1/head-validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ export let ValidatedHeadDef;
// From validator/validator-main.protoascii
const ALLOWED_FONT_REGEX = new RegExp(
'https://cdn\\.materialdesignicons\\.com/' +
'([0-9]+\\.?)+/css/materialdesignicons\\.min\\.css|' +
'[0-9]+(?:\\.[0-9]+)*\\.?/css/materialdesignicons\\.min\\.css|' +
'https://cloud\\.typography\\.com/' +
'[0-9]*/[0-9]*/css/fonts\\.css|' +
'https://fast\\.fonts\\.net/.*|' +
'https://fonts\\.googleapis\\.com/css2?\\?.*|' +
'https://fonts\\.googleapis\\.com/icon\\?.*|' +
'https://fonts\\.googleapis\\.com/earlyaccess/.*\\.css|' +
'https://maxcdn\\.bootstrapcdn\\.com/font-awesome/' +
'([0-9]+\\.?)+/css/font-awesome\\.min\\.css(\\?.*)?|' +
'https://(use|pro)\\.fontawesome\\.com/releases/v([0-9]+\\.?)+' +
'[0-9]+(?:\\.[0-9]+)*\\.?/css/font-awesome\\.min\\.css(\\?.*)?|' +
'https://(use|pro)\\.fontawesome\\.com/releases/v[0-9]+(?:\\.[0-9]+)*\\.?' +
'/css/[0-9a-zA-Z-]+\\.css|' +
'https://(use|pro)\\.fontawesome\\.com/[0-9a-zA-Z-]+\\.css|' +
'https://use\\.typekit\\.net/[\\w\\p{L}\\p{N}_]+\\.css'
Expand Down
35 changes: 35 additions & 0 deletions extensions/amp-a4a/0.1/test/test-head-validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,41 @@ describes.realWin('head validation', {amp: true}, (env) => {
);
});

it('keeps versioned material-design and font-awesome font links', () => {
const preloadStub = env.sandbox.stub(
Services.preconnectFor(env.win),
'preload'
);
const urls = [
'https://cdn.materialdesignicons.com/5.4.55/css/materialdesignicons.min.css',
'https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css',
'https://use.fontawesome.com/releases/v5.15.4/css/all.css',
];
head.innerHTML = urls
.map((href) => `<link href="${href}" rel="stylesheet">`)
.join('\n');
const validated = processHead(env.win, adElement, head);
expect(validated.head.querySelectorAll('link')).to.have.length(
urls.length
);
urls.forEach((href) =>
expect(preloadStub).calledWith(env.ampdoc, href)
);
});

it('rejects a font link with a long unterminated version run', () => {
const preloadStub = env.sandbox.stub(
Services.preconnectFor(env.win),
'preload'
);
const href =
'https://use.fontawesome.com/releases/v' + '9'.repeat(40) + '!';
head.innerHTML = `<link href="${href}" rel="stylesheet">`;
const validated = processHead(env.win, adElement, head);
expect(validated.head.querySelector('link')).not.to.exist;
expect(preloadStub).not.to.be.called;
});

it('does not allow arbitrary font providers', () => {
const preloadStub = env.sandbox.stub(
Services.preconnectFor(env.win),
Expand Down