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

JSON formatting issues with the Shopify Github Integration #373

Open
eddysims opened this issue Apr 2, 2024 · 9 comments
Open

JSON formatting issues with the Shopify Github Integration #373

eddysims opened this issue Apr 2, 2024 · 9 comments
Labels
area:prettier-plugin Bug Something isn't working Severity: 3 lowest severity for theme related bug

Comments

@eddysims
Copy link

eddysims commented Apr 2, 2024

Describe the bug

When using the shopify github integration, I am getting back file urls as an escaped string. Then when running prettier, it is removing the \ from the url.

Unformatted source

shopify:\/\/shop_images\/Logo_2bb829935e.webp

Expected output

shopify:\/\/shop_images\/Logo_2bb829935e.webp

Actual output

shopify://shop_images/Logo_2bb829935e.webp

Debugging information

  • OS [e.g. Windows, Mac, Linux]
  • Version [e.g. 0.1.0]

Additional context

Here is my prettier config:

//.prettierrc.json
{
  "printWidth": 120,
  "singleQuote": true,
  "overrides": [
    {
      "files": "*.liquid",
      "options": {
        "singleQuote": false
      }
    }
  ],
  "plugins": ["@shopify/prettier-plugin-liquid", "prettier-plugin-tailwindcss"]
}
@eddysims eddysims added the Bug Something isn't working label Apr 2, 2024
@charlespwd
Copy link
Contributor

charlespwd commented Apr 3, 2024

Known issue, getting fixed soon 🙏 It's a platform thing. The platform was putting them there to avoid XSS attacks in the case the JSON was dumped in an HTML document.

e.g.

{
  "thing": "</script><script>console.log('hello world');</script>"
}
<html>
  <script type="application/json">
    {
      "thing": "</script><script>console.log('hello world');</script>"
    }
  </script>
</html>

That would actually run the code in the JSON document here. The fix? Backslash all the / in the JSON doc so that the script can't run when dumped in the HTML doc.

{
  "thing": "<\/script><script>console.log('hello world');<\/script>"
}
<html>
problem solved!
  <script type="application/json">
    {
      "thing": "<\/script><script>console.log('hello world');<\/script>"
    }
  </script>
</html>

Thing is, most of our "platform JSON" docs you can't dump directly into your HTML docs, so it's an unnecessary precaution. But we gotta do it carefully.

@charlespwd
Copy link
Contributor

Closing as duplicate

@eddysims
Copy link
Author

eddysims commented Apr 3, 2024

@charlespwd I see you closed this as duplicate. Do you have a reference to another place I can follow along with this?

@charlespwd
Copy link
Contributor

It's an internal issue. Afraid I can't. This is a platform bug :/ the prettier plugin is working as intended 😅

It is on our roadmap to fix this though. You're definitely not the only one annoyed by that.

@knjshimi
Copy link

knjshimi commented Apr 3, 2024

Hey @charlespwd , so it's completely fine to let prettier format the json file (unescaping forward dashes) when working with local themes, right?

@eddysims
Copy link
Author

eddysims commented Apr 3, 2024

@charlespwd Thank you for the update

@zrisher
Copy link

zrisher commented Apr 16, 2024

Wish this wasn't closed. Had the same issue, took a while to find this because it wasn't listed as an open issue.

Even if Shopify has an internal issue to track this, it's helpful to keep it open for the general public to track until it is fixed.

@charlespwd
Copy link
Contributor

Fair!

@charlespwd charlespwd reopened this Apr 16, 2024
@jamesmengo jamesmengo transferred this issue from Shopify/prettier-plugin-liquid Jun 20, 2024
@jamesmengo jamesmengo added Severity: 3 lowest severity for theme related bug and removed untriaged labels Jul 4, 2024
@NathanRutilyDev
Copy link

Hello there, i've still got this issue on HTML tag escaped like this :

What Shopify's waiting :

"results_use_fewer_filters_html": "Use fewer filters or <a class=\"{{ class }}\" href=\"{{ link }}\">remove all<\/a>"

Prettier output :

"results_use_fewer_filters_html": "Use fewer filters or <a class=\"{{ class }}\" href=\"{{ link }}\">remove all</a>"

And the problem is when I do a CLI command like shopify theme dev --theme-editor-sync, it keeps getting .json files with these HTML escape, prettier format it and send it again, and it does an infinite loop .. 😢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:prettier-plugin Bug Something isn't working Severity: 3 lowest severity for theme related bug
Projects
None yet
Development

No branches or pull requests

6 participants