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

Wildcard in reloadableScripts in yii.js allows 0 characters #13306

Closed
arogachev opened this issue Jan 1, 2017 · 3 comments · Fixed by #13611
Closed

Wildcard in reloadableScripts in yii.js allows 0 characters #13306

arogachev opened this issue Jan 1, 2017 · 3 comments · Fixed by #13611
Assignees
Labels
status:ready for adoption Feel free to implement this issue. type:bug Bug
Milestone

Comments

@arogachev
Copy link
Contributor

arogachev commented Jan 1, 2017

I found this issue during writing tests for yii.js.

Currently in yii.js we have reloadableScripts property used in initScriptFilter() function. It supports wildcards since ea0c6d7:

/**
 * List of JS or CSS URLs that can be loaded multiple times via AJAX requests.
 * Each item may be represented as either an absolute URL or a relative one.
 * Each item may contain a wildcart matching character `*`, that means one or more
 * any characters on the position. For example:
 *  - `/css/*.js` will match any file ending with `.js` in the `css` directory of the current web site
 *  - `http*://cdn.example.com/*` will match any files on domain `cdn.example.com`, loaded with HTTP or HTTPS
 *  - `/js/myCustomScript.js?realm=*` will match file `/js/myCustomScript.js` with defined `realm` parameter
 */
reloadableScripts: [],

However, this statement in JSDoc:

Each item may contain a wildcart matching character *, that means one or more * any characters on the position.

contradicts with reality.

0 characters is allowed, so when we set:

yii.reloadableScripts = ['/js/*.js'];

/js/.js will be a valid combination.

Example for easier reproducing:

function escapeRegExp(str) {
    return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
}

var rule = '/js/*.js';
var url = '/js/.js';
var match = new RegExp("^" + escapeRegExp(rule).split('\\*').join('.*') + "$").test(url);

match will have a value true. Looks like a bug for me.

@SilverFire SilverFire added type:bug Bug status:ready for adoption Feel free to implement this issue. labels Jan 2, 2017
@samdark
Copy link
Member

samdark commented Jan 2, 2017

Agree it's a bug.

@arogachev
Copy link
Contributor Author

OK, I can take a look at this, but after merging #13317 to prevent merge conficts.

@arogachev
Copy link
Contributor Author

Sorry, I mean #13316.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:ready for adoption Feel free to implement this issue. type:bug Bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants