pypugjs icon indicating copy to clipboard operation
pypugjs copied to clipboard

Double quotes in attribute (carry-over bug from pyjade issue #132)

Open dol-sen opened this issue 4 years ago • 2 comments

  • pypugjs version: 5.9.4
  • Django version:
  • Python version: any
  • Operating System: linux

Description

In its current form, pyjade converts

div(ng-hide='status == "Live"') into

It seems like this can be fixed by changing line 124 of nodes.py to something like:

return ("'%s'" if '"' in string else '"%s"') % string or by escaping attributes. Normal jade turns such an attribute into:

What I Did

I have submitted a patch for buildbot for it to miggrate from the unmaintained pyjade depedncy to your pypugjs package. It turns out they have an outstanding pyjade bug which affects them. I just checked your pypugjs code. The affected code (class Tag(Node) static() ) is identical aside from some minor formatting style changes.

So, that bug also still applies to your code.

https://github.com/syrusakbary/pyjade/issues/132

dol-sen avatar May 15 '20 08:05 dol-sen

That's a rather old bug. 🙄 Could you submit a PR here? This way you can have a new version in minutes.

kakulukia avatar May 15 '20 08:05 kakulukia

What about this workaround https://github.com/syrusakbary/pyjade/issues/132#issuecomment-30263351?

kakulukia avatar May 15 '20 22:05 kakulukia

switching the quotes is often not an option because json requires double quotes, hence something like this cannot be done with pug right now

<div hx-get="/example" hx-headers='{"myHeader": "My Value"}'>Get Some HTML, Including A Custom Header in the Request</div>

stheid avatar May 17 '24 15:05 stheid

Well, in case you manage to submit a PR, i will merge it.

kakulukia avatar May 17 '24 16:05 kakulukia

please dont blindly merge it though :D i have no experience with the repo. i cant promise the code has no adverse regressions. But maybe with an experienced eye thats easy to judge. its just 2 lines commented out in the end. I can clean that up further if you think its correct.

stheid avatar May 18 '24 16:05 stheid

It sounds like you did not run the tests?

kakulukia avatar May 18 '24 17:05 kakulukia

85 failed tests :/

kakulukia avatar May 19 '24 07:05 kakulukia

can you let me know how to run the tests? i dont have much time to invest into that unfortunately. but maybe i can spare a couple of hours today. I assume you also cant really look into it, right?

Can you give me a gist, what the idea behind this "static attribute" is so i can better understand how my change effects the codebase. if not i will try to grasp it myself.

stheid avatar May 19 '24 09:05 stheid

You have to run

make test

kakulukia avatar May 19 '24 10:05 kakulukia

i think i fixed all tests and added a new one reflecting the change

attr='value' -> attr="value" but attr='{"k": "v"}' -> attr='{"k": "v"}'

stheid avatar May 19 '24 12:05 stheid

New version has been published. You are welcome to test it .

kakulukia avatar May 22 '24 10:05 kakulukia