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

HTML attribute quotes are switched from '->" on published posts #10793

Closed
bzoel opened this issue Jun 18, 2019 · 8 comments
Closed

HTML attribute quotes are switched from '->" on published posts #10793

bzoel opened this issue Jun 18, 2019 · 8 comments
Assignees
Labels
affects:api Affects the Ghost API bug [triage] something behaving unexpectedly help wanted [triage] Ideal issues for contributors to help with server / core Issues relating to the server or core of Ghost

Comments

@bzoel
Copy link

bzoel commented Jun 18, 2019

Issue Summary

Running Ghost 2.23.4/2.5.0 on Ubuntu - the exact HTML I enter into the editor is modified on the frontend page.

To Reproduce

I entered the following HTML block into the editor - note the single quotes.
ghost-editor

<span class="text-success" data-toggle="typed" data-options='{"strings": ["item1", "item2"]}'></span>.

On the front end, single quotes are reflected as double quotes
ghost-frontend

<!--kg-card-begin: html--><span class="text-success" data-toggle="typed" data-options="{"strings": ["item1", "item2"]}"></span>.<!--kg-card-end: html-->

Technical details:

  • Ghost Version: 2.25.0
  • Node Version: 10.16.0
  • Browser/OS: Chrome/Firefox on Windows
  • Database: MySQL & SQLite (dev)
@kevinansfield
Copy link
Contributor

kevinansfield commented Jun 18, 2019

@billyzoellers how are you inspecting the code output? I've just checked this and I can't reproduce. In Chrome's web inspector it appears as though there are double quotes because its inspector automatically changes them as it always uses double quotes for attribute values:

Screenshot 2019-06-18 at 16 03 54

However, looking at the raw data in the response from Ghost the single quotes are preserved:

Screenshot 2019-06-18 at 16 04 31

@kevinansfield kevinansfield added the needs:info [triage] Blocked on missing information label Jun 18, 2019
@bzoel
Copy link
Author

bzoel commented Jun 18, 2019

@kevinansfield I as looking in view source in Chrome. I see the same issue in view source in Firefox as well.

'data-options' is being parsed by a js script that is throwing an error due to the quotes, so I believe the 'bad' HTML is making it to that js script somehow.

I have confirmed that if I hardcode the HTML onto the .hbs template, things work as expected - and when hardcoded, view source shows the single quotes as expected.

@kevinansfield
Copy link
Contributor

kevinansfield commented Jun 18, 2019

Hmm, this is very strange. I can only see the '->" switch happening when a published post served. After putting the post back to draft without changing the contents, no switch is apparent.

It appears this is not related to the editor at all, the data saved in the HTML card inside mobiledoc is always correct, as is the rendered html field. There is something in the handlebars rendering layer that is causing the problem 🤔

@kevinansfield kevinansfield changed the title Editor - HTML card not reflected on page correctly HTML attribute quotes are switched from '->" on published posts Jun 18, 2019
@kevinansfield kevinansfield added bug [triage] something behaving unexpectedly server / core Issues relating to the server or core of Ghost and removed needs:info [triage] Blocked on missing information labels Jun 18, 2019
@kevinansfield
Copy link
Contributor

kevinansfield commented Jun 18, 2019

There is something in the handlebars rendering layer that is causing the problem 🤔

Scratch that, it's in the API layer rather than the handlebars layer. When performing API requests to the v2 Admin/Content APIs for the post in question the quotes are returned incorrectly in the html field...

➜ curl 'http://ghost.blog/ghost/api/v2/content/posts/5d08fc7b26720fe7f85df7d0/?formats=html&key=95bb077bf727261b118b0c72e8' | jq 
######################################################################## 100.0%
{
  "posts": [
    {
      ...
      "html": "<!--kg-card-begin: html--><span class=\"text-success\" data-toggle=\"typed\" data-options=\"{\"strings\": [\"item1\", \"item2\"]}\"></span><!--kg-card-end: html--><p>Testing</p>",
      ...

The key point being data-options=\"{.

The data in the database is correct:

<!--kg-card-begin: html--><span class="text-success" data-toggle="typed" data-options='{"strings": ["item1", "item2"]}'></span><!--kg-card-end: html--><p>Testing</p>

The v0.1 Public API does not mangle quotes.

@kevinansfield kevinansfield added the affects:api Affects the Ghost API label Jun 18, 2019
@bzoel
Copy link
Author

bzoel commented Jun 18, 2019

@kevinansfield Interesting! I can confirm that draft mode works for me as well.

@kevinansfield kevinansfield added the help wanted [triage] Ideal issues for contributors to help with label Jun 18, 2019
@kevinansfield
Copy link
Contributor

kevinansfield commented Jun 18, 2019

Adding some extra context, the mangling is much worse if you try to escape the quotes with backslashes...

html card content:

<span class="text-success" data-toggle="typed" data-options="{\"strings\": [\"item1\", \"item2\"]}"></span>.

becomes:

<!--kg-card-begin: html--><span class="text-success" data-toggle="typed" data-options="{\" strings\":="" [\"item1\",="" \"item2\"]}"=""></span>.<!--kg-card-end: html-->

@billyzoellers the core team is unlikely to get to this until at least next Monday but maybe a contributor will get there first 😄 In the meantime you can workaround the issue by using html-escape codes if that's possible (html escaped chars appear as the actual char to JS when reading attributes):

<span class="text-success" data-toggle="typed" data-options="{&quot;strings&quot;: [&quot;item1&quot;, &quot;item2&quot;]}"></span>.

@kevinansfield
Copy link
Contributor

This issue is now being tracked in our SDK package repo TryGhost/SDK#124

kevinansfield added a commit to kevinansfield/Ghost that referenced this issue Aug 15, 2019
refs TryGhost#10793

- fixes `urlUtils.htmlRelativeToAbsolute` mangling attribute quote styles and removing indentation
kevinansfield added a commit that referenced this issue Aug 15, 2019
refs #10793

- fixes `urlUtils.htmlRelativeToAbsolute` mangling attribute quote styles and removing indentation
@kevinansfield
Copy link
Contributor

This issue was resolved via #11027

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects:api Affects the Ghost API bug [triage] something behaving unexpectedly help wanted [triage] Ideal issues for contributors to help with server / core Issues relating to the server or core of Ghost
Projects
None yet
Development

No branches or pull requests

2 participants