Request to limit scope of functions in validator.js
See original GitHub issueWhat’s the issue?
It seems that functions in validator.js are escaping into the global namespace.
How do we reproduce the issue?
- Navigate to an AMP page like this, with
#development=1
appended to the URL. - Open the browser’s console, and enter
wp
. - Expected:
wp
is not defined - Actual:
wp
is a function:
ƒ wp(a){rp.call(this);this.name=a;this.value=[];this.b=!1;this.o=34}
It looks like this script leaks functions into the global namespace:
https://cdn.ampproject.org/v0/validator.js
There are other functions leaked, like aa
.
Maybe that script is intended for development only, as it seems that it’s not requested if #development=1
isn’t appended. But it would really help us with this issue on the AMP WordPress plugin:
https://github.com/Automattic/amp-wp/issues/843
We’re working on validating AMP in the WordPress editor.
What browsers are affected?
Chrome 63.0.3239.132
Which AMP version is affected?
Thanks a lot for your help 😄
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Is it possible to restrict the scope of a javascript function?
Run the code in an iframe hosted on a different Origin. This is the only way to guarantee that untrusted code is sandboxed...
Read more >validate.js
Validate.js provides a declarative way of validating javascript objects. It is unit tested with 100% code coverage and can be considered fit for...
Read more >Client-side form validation - Learn web development | MDN
Client-side form validation sometimes requires JavaScript if you want to customize styling and error messages, but it always requires you to think carefully ......
Read more >Variable scope - Manual - PHP
There is no limit to the number of global variables that can be manipulated by a function. A second way to access variables...
Read more >Spring Validation Example - Spring MVC Form Validator
When we accept user inputs in any web application, it becomes necessary to validate them. We can validate the user input at the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think we can get a fix out for this fairly quickly. @powdercloud has a prototype, but we need to get it through a release. Thanks for the report.
Thank You
Hi @powdercloud and @Gregable, Thanks a lot for fixing this. As you mentioned, validator.js is wrapped in a function, and functions like
wp
aren’t leaked.