-
-
Notifications
You must be signed in to change notification settings - Fork 45
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
Do not validate language in extended filename parameter #70
base: master
Are you sure you want to change the base?
Conversation
db288e7
to
bb78e30
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one nit.
* value-chars = *( pct-encoded / attr-char ) | ||
* pct-encoded = "%" HEXDIG HEXDIG | ||
* attr-char = ALPHA / DIGIT | ||
* / "!" / "#" / "$" / "&" / "+" / "-" / "." | ||
* / "^" / "_" / "`" / "|" / "~" | ||
* @private | ||
*/ | ||
|
||
var EXT_VALUE_REGEXP = /^([A-Za-z0-9!#$%&+\-^_`{}~]+)'(?:[A-Za-z]{2,3}(?:-[A-Za-z]{3}){0,3}|[A-Za-z]{4,8}|)'((?:%[0-9A-Fa-f]{2}|[A-Za-z0-9!#$&+.^_`|~-])+)$/ | ||
var EXT_VALUE_REGEXP = /([A-Za-z0-9!#$%&+\-^_`{}~]+)'(?:[^']*)'((?:%[0-9A-Fa-f]{2}|[A-Za-z0-9!#$&+.^_`|~-])+)$/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a helpful visualization tool I use to make sure I follow what these longer regex's do:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yar, I prefer to break regex down into pieces you can semantically name like:
// Define each part of the regex:
const charset = "([A-Za-z0-9!#$%&+\\-^_`{}~]+)"; // Captures the charset (e.g. "UTF-8")
const openQuote = "'"; // Literal opening quote
const language = "(?:[^']*)"; // Matches any characters except a single quote (ignores language)
const closeQuote = "'"; // Literal closing quote
const valueChars = "((?:%[0-9A-Fa-f]{2}|[A-Za-z0-9!#$&+.^_`|~-])+)$"; // Captures the percent-encoded value-chars
// Combine them into the final regex string:
const regexStr = "^" + charset + openQuote + language + closeQuote + valueChars;
// Then compile the regex:
const EXT_VALUE_REGEXP = new RegExp(regexStr);
But it does make it harder to just copy the full thing out
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like to write parsers instead of regex, solves the same problems. But yeah, until someone opens a PR to convert all this regex to a parser I am good with doing what you propose here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the approach Jon proposes, it really helps with readability for people who are not very good with regex.
Oh, we should discuss the semver-ness of this. I think because this used to throw and now will not, this is a breaking change. How do you feel about that? |
Co-authored-by: Wes Todd <[email protected]>
Semver major, same input has different output |
closes #47