-
Notifications
You must be signed in to change notification settings - Fork 644
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
Allow regular expression for an HTML attribute value #386
Comments
Thanks for opening the issue @tinovyatkin, but that is the expected behavior since Marko is using the JavaScript rules for parsing a String attribute value. This means that JavaScript escape sequences starting with the <input type="text" pattern="\\w{2,20}" /> While this is not a bug in Marko, I admit that the escaping of those characters is less than ideal. What are your thoughts on enhancing Marko to allow a JavaScript regular expression for the attribute value?: <input type="text" pattern=/\w{2,20}/ /> (we could update the compiler so that the output would be as expected) |
I think accepting native RegEx as value will looks logical and very appropriate! |
Also, I'm not sure that this pattern attribute will work in same way in all browsers after escaping |
We should do this. It's come up before. It should be as simple as adding the following to the if(attr instanceof RegExp) {
let str = attr.toString();
return str.slice(1, str.lastIndexOf('/'));
} The only thing is that html style regex don't support flags, so I'm thinking we just drop them? |
Fixes #386 - Allow regular expression for an HTML attribute value
Bug Report
Compiler throws an error on valid RegEx expressions in HTML5
pattern
attribute forinput
elements.Context
Given following code example
Expected Behavior
Compile normally, as it valid attribute value
Actual Behavior
Throws Error
'Invalid string ("\\w{1,30}"): SyntaxError: Unexpected token w in JSON at position 2'
Additional Info
Your Environment
"marko": "^4.0.0-beta.1"
node.js 7.0
Stack Trace
The text was updated successfully, but these errors were encountered: