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

input pattern requires double-escaping #830

Closed
shanewholloway opened this issue Dec 7, 2012 · 6 comments · Fixed by #963
Closed

input pattern requires double-escaping #830

shanewholloway opened this issue Dec 7, 2012 · 6 comments · Fixed by #963
Labels

Comments

@shanewholloway
Copy link

Trying to figure out why my input pattern was not working, I asked html2jade to translate the following input pattern:

> html2jade
<input pattern='\S+(\.\S+)+'>

html
body
    input(pattern='\S+(\.\S+)+')

But it does not work as advertised:

> jade
input(pattern='\S+(\.\S+)+')

<input pattern="S+(.S+)+"/>

Single escaping does not work:

> jade
input(pattern='\\S+(\\.\\S+)+')

<input pattern="S+(.S+)+"/>

Only after double-escaping the slashes do I get the desired escaping for my input pattern:

> jade
input(pattern='\\\\S+(\\\\.\\\\S+)+')

<input pattern="\S+(\.\S+)+"/>
@tj
Copy link
Contributor

tj commented Dec 7, 2012

attribute strings are regular js strings, so single escapes should work, something funky going on otherwise

@shanewholloway
Copy link
Author

My sentiments exactly — I was very surprised that single escaping didn't work. It probably means that the attribute string is being parsed twice on it's way to the output.

On Dec 7, 2012, at 7:09 AM, TJ Holowaychuk notifications@github.com wrote:

attribute strings are regular js strings, so single escapes should work, something funky going on otherwise


Reply to this email directly or view it on GitHub.

@mashihua
Copy link

HI, visionmedia. After I read the source https://github.com/visionmedia/jade/blob/master/lib/compiler.js#L571 .
Found give val.buf value to 'pattern':('\S+(.\S+)+'), the buf become { pattern: 'S+(.S+)+' } after eval invoked。

@ForbesLindesay
Copy link
Member

The problem is that we're 'undoing' the escaping when we eval. For example we convert '\n' to an actual new line I assume.

macat added a commit to macat/jade that referenced this issue Apr 15, 2013
* upstream/master: (26 commits)
  if watching and compile failed don't bomb the watch
  improve the hygiene of compiled functions
  Fix expression buffering bug
  Add test case for pugjs#830 pugjs#847
  Escape JavaScript strings as late as possible
  Add some tests that wouldn't have passed before
  Fix interpolation in blocks of text
  Fix attribute interpolation
  Use character-parser for js-expression parsing
  move filters to an external library
  simplifying escaping of newlines so it only happens in text escaping
  update jade(1) reference to include the watch option
  tests
  only replace new lines if not a js file
  fix indentation issue
  Don't lock coffee-script dev-dependency
  Mention include file extension filters in readme
  Update slim repo url
  Revert "Eliminate useless var definitions."
  Release 0.28.2
  ...
ddopson pushed a commit to wavii/jade that referenced this issue Apr 23, 2013
@whaaaley
Copy link

I'm still experiencing this bug.

@ForbesLindesay
Copy link
Member

You should have to do a single layer of escaping (because the value is a JavaScript expression):

input(pattern='\\S+(\\.\\S+)+')

should produce:

<input pattern="\S+(\.\S+)+"/>

Which is working for me. If that doesn't work for you, please open a new issue. I'm locking this issue as this bug was definitely fixed, any new bugs should be opened as a fresh issue.

@pugjs pugjs locked and limited conversation to collaborators Apr 13, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants