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 the regex used to detect name and argument part of a variable. #6566

Merged
merged 1 commit into from
Dec 8, 2016
Merged
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
4 changes: 2 additions & 2 deletions extensions/amp-analytics/0.1/amp-analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -527,13 +527,13 @@ export class AmpAnalytics extends AMP.BaseElement {
if (!key) {
return {name: '', argList: ''};
}
const match = key.match(/([^(]*)(\([^)]*\))?/);
const match = key.match(/^(?:([^ ]*)(\([^)]*\))|.+)$/);
if (!match) {
const TAG = this.getName_();
user().error(TAG,
'Variable with invalid format found: ' + key);
}
return {name: match[1], argList: match[2] || ''};
return {name: match[1] || match[0], argList: match[2] || ''};
}

/**
Expand Down
21 changes: 21 additions & 0 deletions extensions/amp-analytics/0.1/test/test-amp-analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -1042,4 +1042,25 @@ describe('amp-analytics', function() {
});
});
});

describe('getNameArgs:', () => {

function check(input, name, argList) {
it('can parse ' + name, () => {
const analytics = getAnalyticsTag(trivialConfig);
expect(analytics.getNameArgs_(input)).to.deep.equal({name, argList});
});
}

check('abc', 'abc', '');
check('client id', 'client id', '');
check('client id()', 'client id()', '');
check('client id (abc)', 'client id (abc)', '');


check('clientId()', 'clientId', '()');
check('clientId(abc)', 'clientId', '(abc)');
check('clientId(abc,def)', 'clientId', '(abc,def)');
check('clientId(abc, def)', 'clientId', '(abc, def)');
});
});