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

Whitelist of Variable Substitutions #3

Open
wants to merge 68 commits into
base: master
Choose a base branch
from
Open

Whitelist of Variable Substitutions #3

wants to merge 68 commits into from

Conversation

hamousavi
Copy link
Owner

If a whitelist of variables is provided using meta tags for example as follows
<meta name="amp-variable-substitution-whitelist" content="RANDOM,TIMEZONE">
then the runtime should respect it. In order to do this we parse the meta tag in GlobalVariableSource.

@hamousavi
Copy link
Owner Author

@raywainman @zhangsu

I managed to add some functional tests. But still have difficulty in adding functional tests to test-url-replacements.js. For some reason the test case cannot find the "meta tag" when I embed it to the window.

rsimha and others added 13 commits February 5, 2018 12:57
* document batching features

* add reportWindow

* minor fixes

* add refer to

* fix test
* 📖 add AMP emoji conventional changelogs

* apply recommendations
…project#13266)

* Rename lightbox-viewer to lightbox-gallery

* Rename lightbox css from viewer to gallery

* Remove dead manual test pages
* Return play promise from playFn to ensure media playback is not interrupted.

* Refactor playFn to always return a promise.  Improve documentation.

* Use closure so the proper context is set on the distance function.

* Add debug messages

* Remove muted property change, since this is in a separate PR

* Fix merge
* Component skeleton

* move files into amp-story

* clean up example

* remove bad link

* bad mock test

* clean up
* fix dist with alias

* change minimal_set usage

* fix documentation

* refactor print logic

* rename

* update function description

// Cache the whitelist of allowed AMP actions (if provided).
if (meta) {
this.ampVariableSubstitutionWhitelist_ =
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This field needs JSDoc.

It might be better to move the initialization logic to a helper method and use null as the default value for this field. ?string is usually more idiomatic than string|undefined.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -74,6 +74,22 @@ export class GlobalVariableSource extends VariableSource {
/** @const {!./ampdoc-impl.AmpDoc} */
this.ampdoc = ampdoc;

// A meta[name="amp-action-whitelist"] tag, if present, contains,
// in its content attribute, a whitelist of actions on the special AMP target.
if (this.ampVariableSubstitutionWhitelist_ === undefined
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is in a constructor, and there's no previous assignment to ampVariableSubstitutionWhitelist_, so this condition should always be true.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

// A meta[name="amp-action-whitelist"] tag, if present, contains,
// in its content attribute, a whitelist of actions on the special AMP target.
if (this.ampVariableSubstitutionWhitelist_ === undefined
&& this.ampdoc.getRootNode() && this.ampdoc.getRootNode().head) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return value of getRootNode() is non-nullable and never undefined, so we shouldn't need to check this.ampdoc.getRootNode() ...

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

if (meta) {
this.ampVariableSubstitutionWhitelist_ =
meta.getAttribute('content').split(',')
.map(action => action.trim());
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that this code is repeated from the previous PR. Consider extracting this to a utility class.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

@@ -121,6 +121,9 @@ export class VariableSource {

/** @private {boolean} */
this.initialized_ = false;

/** @const @private {!Array<string>|undefined} */
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is private, and if the type checker is doing the correct thing, then subclasses should never be able to access this field... I think we really want a (ideally-abstract) method.

That said, why do we implement the actual meta tag check in the base class instead of here in the base class? Are there other implementations of VariableSource that makes whitelisting using meta tags not make sense?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GlobalVariableSource is the only implementation of VariableSource. So I moved this logic to the base class as you suggested.

gmajoulet and others added 20 commits February 7, 2018 09:13
)

* Linear transitions for media story pages progress bar.

* Unobfuscate the unobfuscated code.
* Updating to new async tag

* Linter fix: imports must be alphabetical
* chore(package): update browserify to version 16.0.0

* chore(package): update lockfile

https://npm.im/greenkeeper-lockfile
* change amp-bind verification to user warning and clarify message

* fix presubmit

* fix test
* Revision bump for ampproject#13036

* Revision bump for ampproject#13073

* Add DEDUPE_ON_MINIFY flags to license tags so that release process can
reduce the number of identical duplicate licenses in the minified
validator.

* Add requires_extension to AttrSpec.

* JSDoc updates.

* Generated validator javascript improvements.

* Add comment to ValidationError hinting at how to render.

* Revision bump for ampproject#12955

* Add new error types for future CSS validation.

* Revision bump for ampproject#12798

* Fix a typo.

* Allow animation-timing-function for keyframes

* Fix typo
* Remove spurious files

* cvializ@ suggested changes

* Fixed Travis CI failures
* Development/debug setup.

* Basic exp setup.

* Header parsing and stuff.

* Client-side changes fin.

* Cleaned PR + tests.

* Undoing yarn stuff.

* Yarn attempt #2.

* Reverting example page.

* lint fix

* PR feedback.

* Undoing changes to test page.

* Merges

* Yarn

* Not calling document.open/close when writing in body and not waiting for onload. Also removed accidentally merged tests.

* Adding back document.open/close into default flow.

* Simplified conditional.

* Adsense support.

* Merges/rebase.

* Alphabetized imports.

* Factored out common code to utils.
@zhangsu
Copy link

zhangsu commented Feb 7, 2018

Could you merge upstream into your master branch? Currently your variable branch includes changes from upstream but master doesn't, so the diff is huge...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.