_hyperscript icon indicating copy to clipboard operation
_hyperscript copied to clipboard

fix(templates): fixed string interpolation in template strings

Open BirdeeHub opened this issue 1 year ago • 6 comments

addresses https://github.com/bigskysoftware/_hyperscript/issues/561

BirdeeHub avatar Oct 04 '24 09:10 BirdeeHub

Edit:

Actually, you still cant escape them...

You couldnt before, but, after this fix you still wont be able to.

Working on a better version now. Hopefully will have in a few days

BirdeeHub avatar Oct 04 '24 12:10 BirdeeHub

Ok, well, it escapes properly in all but 1 case now in my local copy that Im working on.

I know what that case is and why it happens, and I could disgustingly fix it but id rather like... nicely fix it.

`test \${x}`

currently this case fails still in my local copy.

But Im close. I just need to find a good way to fix the last case

BirdeeHub avatar Oct 04 '24 14:10 BirdeeHub

I did have to split up consumeIdentifier and consumeTemplateIdentifier into 2 separate functions though.

Actually, since the current one on here doesnt escape at ALL I will push the updated version in the meantime so you can see where its at.

BirdeeHub avatar Oct 04 '24 15:10 BirdeeHub

When I fix the final escaping case:

`test \${x}`

This PR will be reinstated as no longer a draft.

BirdeeHub avatar Oct 04 '24 15:10 BirdeeHub

https://github.com/BirdeeHub/_hyperscript/blob/3e29b493e3eb032f5177371218b4f6cf18485c27/src/_hyperscript.js#L279-L286

^ this clause is the one catching that 1 case that I havent addressed yet...

BirdeeHub avatar Oct 04 '24 15:10 BirdeeHub

It works now :)

BirdeeHub avatar Oct 04 '24 16:10 BirdeeHub

Thank you for this change, did you run the entire test suite against it?

1cg avatar Oct 20 '24 22:10 1cg

yeah I ran all the tests, I also tried it out in the playground.

I also added the new test which tests many different permutations of the interpolation. In the test I had to double escape because it gets passed through JS first, but in the playground it works as expected, you can escape with \${} and it will not interpolate

Also it seems your test suite fails one of the tests when ran via opening test/index.html file with a browser directly but succeeds if you serve with python or something and then go to the page in the browser? This is unrelated to the interpolation syntax though, I forget which but I think it was the socket one? I just remember the failure making sense when I looked at the code of the offending test.

BirdeeHub avatar Oct 21 '24 11:10 BirdeeHub