Double-quotes HTML-encoded in attribute values · Issue #969 · pugjs/pug · GitHub
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

Double-quotes HTML-encoded in attribute values #969

Closed
es128 opened this issue Apr 18, 2013 · 14 comments
Closed

Double-quotes HTML-encoded in attribute values #969

es128 opened this issue Apr 18, 2013 · 14 comments

Comments

@es128
Copy link

es128 commented Apr 18, 2013

li(ng-repeat='item in collection | orderBy:"order"')
yields
<li ng-repeat="item in collection | orderBy:&quot;order&quot;">
and does not get processed properly by angular.

Backslash-escaping the double-quotes in jade seems to have no effect.

Currently solving this by inverting the single and double-quotes li(ng-repeat="item in collection | orderBy:'order'"), but would like to keep single-quoted attribute definitions to be consistent with the rest of the project.

Seems like it would be better if jade inverted double-quotes wrapped within single-quotes, or just maintained the quote style of the original definition (when variable interpolation is not involved)

@ForbesLindesay
Copy link
Member

The behavior jade has is correct. You could try persuading angularJS to support HTML encoded attributes. Alternatively you could do:

li(ng-repeat='item in collection | orderBy:\'order\'')

@nickperkinslondon
Copy link

This is "correct"? Not for me! This makes Jade quite useless for AngularJS ( or at least clumsy and awkward ), which is a shame. Simply putting the blame on Angular is no solution either! Why would you encode attribute values?

@es128
Copy link
Author

es128 commented Jul 28, 2013

dramatic, much?

li(ng-repeat="item in collection | orderBy:'order'")

@nickperkinslondon
Copy link

well, that's ok, i guess but...is there just no way to get double-quotes inside an attribute value?
...in case I ever find that I really need that?
If not, that seems like a peculiar limitation of the language.

@crissdev
Copy link

Why are you guys complain about this so much? I'm pretty sure that in normal HTML you write attribute values in double quotes. So what's the deal?

<div data-message="Wouldn't this be the way you would code this?"></div>

If you want to use ONLY single quotes then just escape them, as @ForbesLindesay commented above.

@nickperkinslondon
Copy link

Ok, so maybe I can live without the double-quote character, but what about the "less-than" character?
How can I do some angular js like this?

<li ng-class=" { active : thing.score < 50 } ">

It is escaping my less-than character:
This:

li(ng-class=" { active : thing.score < 50 } ")

Gives me this:

<li ng-class=" { active : thing.score &lt; 50 } "></li> 

...which does not work.

How can I do this?
What I want is for my attribute strings to simply be left alone.
Maybe I don't get it...am I missing something?
If I get excited, it's only because Jade seems really cool and I was really hoping it would work well with Angular.js development.
I do appreciate your time, guys.

@ForbesLindesay
Copy link
Member

We have an un-escaped variant for attributes:

li(ng-class!="{active: thing.score < 50 }")

gives

<li ng-class=" { active : thing.score < 50 } "></li> 

You also could try and improve angularJS by making it understand html encoded attributes. It's arguably a bug that it doesn't do so at the moment.

@nickperkinslondon
Copy link

Cool! That helps a lot!
sorry if I missed that in the docs somewhere
That fixes the "less-than" problem, and sticking to double-quotes mostly fixes the quote problem.
I will definitely keep using Jade now for Angular.js development.

I am not convinced, however, that this should be considered a bug in Angular.js.
Angular is designed to work on hand-written html files, right?
Or, at least, files that have the same structure and encoding as actual hand-written html files.
I would think that Angular would say that it is up to you, Jade, to somehow produce the desired output, which is html-encoding in any "text", but no encoding within quoted attributes. The fact that Jade will html-escape any free-floating text is certainly a feature, but html-escaping the contents of quoted attribute values feels more like a bug.

Anyway, thanks a lot for the help!
I will just have to remember to always use != and to always use double-quotes.
( and hope I never need to include a double-quote character inside any attribute value, ever )

@ForbesLindesay
Copy link
Member

The point is that html encoding is the only (correct) way to put double quotes in an html attribute (whether you're generating it with jade or writing it by hand)

@rlidwka
Copy link
Member

rlidwka commented Oct 12, 2013

This is "correct"? Not for me! This makes Jade quite useless for AngularJS ( or at least clumsy and awkward ), which is a shame.

No, it makes AngularJS quite useless, because they are ones who don't support spec.

Vanilla javascript with all the frameworks I know deal with encoded attributes correctly:

console.log($('<input value="test &quot;&lt;&gt;&quot; test"/>')[0].getAttribute('value'))
test "<>" test

console.log($('<input value="test &quot;&lt;&gt;&quot; test"/>').attr('value'))
test "<>" test

I would think that Angular would say that it is up to you, Jade, to somehow produce the desired output, which is html-encoding in any "text", but no encoding within quoted attributes.

Jade is designed to compile to a valid well-formed html. If you want something like this: <li ng-repeat="item in collection | orderBy:"order";"> to support some kind of buggy software, you'd better write it by hand, really.

@crissdev
Copy link

@ rlidwka 👍 It seems Angular guys should fix this issue. Should we consider moving this to their issue tracker?

@es128
Copy link
Author

es128 commented Oct 14, 2013

@crissdev I already did that with angular/angular.js#2525. It was ignored, then auto-closed. But if you are concerned with this issue, it probably would be a good idea to ask for it to be reopened or just make a new issue - let the Angular devs know that more than one person cares about this.

@khaledfathy
Copy link

Dear all
i have problem when i fetch data with angularjs it return but in double quotes i want to remove double quotes because the data is script and i want generate script at run time

Chart Id: {{item.ChartId}} @_<script id="javaScriptValue" type="text/javascript" src="{{item.ChartScript}}"></script>_@

{{ item.ChartScript | limitTo:item.ChartScript.length}}

what can I do?

@khaledfathy
Copy link

Chart Id: {{item.ChartId}}

{{ item.ChartScript | limitTo:item.ChartScript.length}}

i need remove double quotes from html attr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants