question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Weird escape on variables that contains apostrophe

See original GitHub issue

Hi 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: Schermata 2021-05-13 alle 13 19 06

The problem seems to be this escape: Schermata 2021-05-13 alle 13 21 07


Versions

  • Plugin version: Tested on 1.4.0 and 1.5.2
  • Craft version: 3.6.13

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
bencrokercommented, May 13, 2021

Yes I’m also debugging that code right now. You’re right that there is some double escaping going on, reopening this issue.

0reactions
billmncommented, May 13, 2021

@bencroker Great! Thank you 🚀

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found