Weird escape on variables that contains apostrophe
See original GitHub issueHi guys, I noticed that within a Sprig component, variables containing the apostrophe are “escaped”.
I wrote a simple example that highlights the escape difference between Twig and Sprig:
Create a test.twig
file whit this code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel="stylesheet">
</head>
<body>
<main class="h-screen flex items-center justify-center space-x-6">
<div class="border-2 border-blue-500 p-6">
{% set test = "Sprig's test" %}
<div class="text-xl mb-6">Outside Sprig component</div>
<input type="text" value="{{ test }}" class="block border p-3">
<input type="text" value="{{ "Sprig's test" }}" class="block border p-3">
</div>
<div class="border-2 border-yellow-500 p-6">
<div class="text-xl mb-6">Inside Sprig component</div>
{{ sprig('testComponent') }}
</div>
</main>
{{ sprig.script }}
</body>
</html>
Create a testComponent.twig
file whit this code:
{% set test = "Sprig's test" %}
<input type="text" value="{{ test }}" class="block border p-3">
<input type="text" value="{{ "Sprig's test" }}" class="block border p-3">
Now if you load the test.twig
template in the browser (e.g. http://domain/test) you will see this:
The problem seems to be this escape:
Versions
- Plugin version: Tested on 1.4.0 and 1.5.2
- Craft version: 3.6.13
Issue Analytics
- State:
- Created 2 years ago
- Comments:9
Top Results From Across the Web
Escape Mustache variable containing apostrophe for JavaScript
I have a variable ( {{title}} ) which contains an apostrophe. Mustache escapes this as ' . However, the following template results in...
Read more >Escaping Apostrophe... selectively - MSDN - Microsoft
On my master page, I set a variable: LogonUserName = (string)Command.ExecuteScalar();. This may contain an apostrophe.
Read more >Escaping with single-quote (a.k.a. Apostrophes ') character in ...
In a Java format string, for normal cases, where there are a pair of apostrophes surrounding any other characters, the characters they are...
Read more >Testing iOS - How to escape the apostrophe character
I have an experiment that checks for the existence of a string of characters. The problem comes when the string contains an apostrophe...
Read more >Are You Double-Escaping Apostrophes in XOG? | Clarity
You can escape special characters or can use CDATA. ... Odd, I don't recall ever having to escape quotes at all (neither single-quote...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes I’m also debugging that code right now. You’re right that there is some double escaping going on, reopening this issue.
@bencroker Great! Thank you 🚀