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

escape thing inside of code tag #2337

Merged
merged 1 commit into from
Oct 30, 2021
Merged

Conversation

Kevan-Y
Copy link
Contributor

@Kevan-Y Kevan-Y commented Oct 5, 2021

Issue This PR Addresses

Fixes #2322

Type of Change

  • Bugfix: Change which fixes an issue
  • New Feature: Change which adds functionality
  • Documentation Update: Change which improves documentation
  • UI: Change which improves UI

Description

Removed replace-entities.js to fix our current issue but will re-introduce #1091.
Added a regex at end of

to turn > back to >

Checklist

  • Quality: This PR builds and passes our npm test and works locally
  • Tests: This PR includes thorough tests or an explanation of why it does not
  • Screenshots: This PR includes screenshots or GIFs of the changes made or an explanation of why it does not (if applicable)
  • Documentation: This PR includes updated/added documentation to user exposed functionality or configuration variables are added/changed or an explanation of why it does not(if applicable)

Copy link
Contributor

@humphd humphd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is different than what I thought we were discussing. I thought you were going to submit a PR to change the options we pass to the sanitizer so it escapes vs. deletes unknown tags.

I don't think running regexes on the HTML is a good idea.

@Kevan-Y
Copy link
Contributor Author

Kevan-Y commented Oct 5, 2021

This is different than what I thought we were discussing. I thought you were going to submit a PR to change the options we pass to the sanitizer so it escapes vs. deletes unknown tags.

I don't think running regexes on the HTML is a good idea.

But adding the escape will convert tag like <code><text></code> to <code><text></text></code> or <code><text/></code> to <code><text></text></code>
By converting < and > to &lt; and &gt;, it escapes and doesn't not change <code><text></code> to <code><text></text></code>

@Kevan-Y Kevan-Y requested a review from humphd October 5, 2021 15:19
@humphd
Copy link
Contributor

humphd commented Oct 5, 2021

I want to understand the underlying problem here vs. fix one specific case. Consider:

  1. <code><text></code>
  2. <code>&lt;text&gt;</code>

The example in 1. is not valid HTML5, only 2. is. Why are we being dealing with invalid HTML in the first place? Are we being sent it? Or is our feed pipeline producing it somehow?

In the case of your post, I see that we get this: <code>Closed by &lt;short_name_issue_code&gt;.</code>

I think the underlying issue is the fact that the sanitizer is forcing entities to be decoded, see fb55/htmlparser2#105. Undoing this has some interesting security implications.

@manekenpix
Copy link
Member

@Kevan-Y any updates?

@humphd
Copy link
Contributor

humphd commented Oct 12, 2021

I think this is a hard problem. My gut says that we should turn off automatic entity decoding in the sanitizer, which is on by default to catch some edge case bugs. Because we pull content from existing systems vs. ingesting user-defined HTML directly, it's probably safe to accept what comes in and just strip the bits we don't want (e.g., scripts, etc).

@humphd
Copy link
Contributor

humphd commented Oct 13, 2021

Let's try an experiment to change our HTML sanitizer to stop encoding automatically:

htmlparser2 Options

sanitize-html is built on htmlparser2. By default the only option passed down is decodeEntities: true. You can set the options to pass by using the parser option.

@Kevan-Y
Copy link
Contributor Author

Kevan-Y commented Oct 22, 2021

Update:
After some traceback, I notice that the main issue was

const result = entities.decodeHTML(codeElement.innerHTML);
return entities.decodeHTML(result);

Looked at the feed information that we get when something is inside of the code tag, it is in escaped character already, but because of the decode HTML. It turns into an actual character. Which produces turning to actual HTML.
By removing replace-entities.js, the current issue will be fixed but this issue #1091 will be reproducible.
Traced back where it is causing
const { value, language } = hljs.highlightAuto(code.innerHTML);

I think when we pass our code.innerHTML to the hljs.highlightAuto() It's changing for example &gt; to &amp;gt;.
So maybe having a regex at the end

to change it back should be enough to fix that bug.

// Replace the contents with newly marked up syntax highlighting
code.innerHTML = value;
code.innerHTML = value.replace(/\&amp;([a-z]*);/gm, '&$1');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HTML entities can be a lot more than just a-z. Maybe this should be:

/\&amp;([^;]+);/gm

In this case, it matches 1 or more non-semi-colon characters before a semi-colon.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if &amp; is present on its own in the post? Won't this destroy it?

Copy link
Contributor Author

@Kevan-Y Kevan-Y Oct 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the regex, added one more condition if the user input &amp;&lg; it will stay the same. The change only apply for thing e.g, &amp;lt; or &amp;gt; ...

@@ -54,7 +54,8 @@ module.exports = function (dom) {
pre.classList.add('hljs', language);
}

// Convert &amp; followed by another escape character to a single escape character
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment needs more details. It's odd that we're doing this, so we should explain why we have chosen to do it, and what it is fixing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

@@ -53,8 +53,9 @@ module.exports = function (dom) {
if (pre) {
pre.classList.add('hljs', language);
}

// Value from hljs.highlightAuto turn escape character to e.g &lt; to &amp;lt;
// Adding regex to convert &amp; of that escape character back to &
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// Replace the contents with newly marked up syntax highlighting
code.innerHTML = value;
code.innerHTML = value.replace(/\&amp;([^;|^&]+);/gm, '&$1');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've got two cases here: not ; and not &. Can we get test coverage of both?

Also, there are about 8 issues filed on this, which reference various blog posts in the wild that have broken. Can you create some more tests based on those cases? It would be good to know that your code fixes them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some test cases. Some issues filed are duplicated from others so combined into 1 test case.

You've got two cases here: not ; and not &. Can we get test coverage of both?

Not sure if it is possible I can test for like &amp;&amp; or ;&amp;lt; to stay the same when calling the whole process but not test &amp;lt; to turn &lt; by calling the whole process since this is happening inside of syntax-highlight.js with value. Like for example if we pass &amp;lt; to hljs.highlightAuto(code.innerHTML); it will turn to &amp;amp;lt; then with the regex it will turned back to &amp;lt;
We can cover that if we create a test case to test this specific regex. But I don't think we need it

@humphd
Copy link
Contributor

humphd commented Oct 24, 2021

@Kevan-Y can you rebase and fix the conflict please?

@Kevan-Y
Copy link
Contributor Author

Kevan-Y commented Oct 24, 2021

@Kevan-Y can you rebase and fix the conflict please?

Rebased the branch to master, squash commit together to make it looks nicer, and fixed conflict

@humphd
Copy link
Contributor

humphd commented Oct 24, 2021

Did you rebase onto the right commit? Looks like you've got issues with removeDevToFullscreen, which I think we ripped out quite a while ago.

Summary of all failing tests
FAIL test/feed.test.js
  ● Post data class tests › Get and Set Feed objects from database › Removing feeds should also remove posts

    ReferenceError: removeDevToFullscreen is not defined

      41 |   lazyLoad(dom);
      42 |   // Deal with "Enter fullscreen mode Exit fullscreen mode" text from dev.to bug
    > 43 |   removeDevToFullscreen(dom);
         |   ^
      44 |
      45 |   // Return the resulting HTML
      46 |   return dom.window.document.body.innerHTML;

      at processHTML (src/backend/utils/html/index.js:43:3)
      at _callee$ (src/backend/data/post.js:134:14)
      at tryCatch (node_modules/regenerator-runtime/runtime.js:63:40)
      at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:294:22)
      at Generator.next (node_modules/regenerator-runtime/runtime.js:119:21)
      at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
      at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:25:9)
      at node_modules/@babel/runtime/helpers/asyncToGenerator.js:32:7
      at Function.<anonymous> (node_modules/@babel/runtime/helpers/asyncToGenerator.js:21:12)

FAIL test/post.test.js
  ● Post data class tests › Post.createFromArticle() tests › should work with real world RSS

    ReferenceError: removeDevToFullscreen is not defined

      41 |   lazyLoad(dom);
      42 |   // Deal with "Enter fullscreen mode Exit fullscreen mode" text from dev.to bug
    > 43 |   removeDevToFullscreen(dom);
         |   ^
      44 |
      45 |   // Return the resulting HTML
      46 |   return dom.window.document.body.innerHTML;

      at processHTML (src/backend/utils/html/index.js:43:3)
      at _callee$ (src/backend/data/post.js:134:14)
      at tryCatch (node_modules/regenerator-runtime/runtime.js:63:40)
      at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:294:22)
      at Generator.next (node_modules/regenerator-runtime/runtime.js:119:21)
      at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
      at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:25:9)
      at node_modules/@babel/runtime/helpers/asyncToGenerator.js:32:7
      at Function.<anonymous> (node_modules/@babel/runtime/helpers/asyncToGenerator.js:21:12)

  ● Post data class tests › Post.createFromArticle() tests › Post.createFromArticle() with missing date should not throw

    ReferenceError: removeDevToFullscreen is not defined

      41 |   lazyLoad(dom);
      42 |   // Deal with "Enter fullscreen mode Exit fullscreen mode" text from dev.to bug
    > 43 |   removeDevToFullscreen(dom);
         |   ^
      44 |
      45 |   // Return the resulting HTML
      46 |   return dom.window.document.body.innerHTML;

      at processHTML (src/backend/utils/html/index.js:43:3)
      at _callee$ (src/backend/data/post.js:134:14)
      at tryCatch (node_modules/regenerator-runtime/runtime.js:63:40)
      at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:294:22)
      at Generator.next (node_modules/regenerator-runtime/runtime.js:119:21)
      at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
      at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:25:9)
      at node_modules/@babel/runtime/helpers/asyncToGenerator.js:32:7
      at Function.<anonymous> (node_modules/@babel/runtime/helpers/asyncToGenerator.js:21:12)

  ● Post data class tests › Post.createFromArticle() tests › Post.createFromArticle() with missing title should use Untitled

    ReferenceError: removeDevToFullscreen is not defined

      41 |   lazyLoad(dom);
      42 |   // Deal with "Enter fullscreen mode Exit fullscreen mode" text from dev.to bug
    > 43 |   removeDevToFullscreen(dom);
         |   ^
      44 |
      45 |   // Return the resulting HTML
      46 |   return dom.window.document.body.innerHTML;

      at processHTML (src/backend/utils/html/index.js:43:3)
      at _callee$ (src/backend/data/post.js:134:14)
      at tryCatch (node_modules/regenerator-runtime/runtime.js:63:40)
      at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:294:22)
      at Generator.next (node_modules/regenerator-runtime/runtime.js:119:21)
      at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
      at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:25:9)
      at node_modules/@babel/runtime/helpers/asyncToGenerator.js:32:7
      at Function.<anonymous> (node_modules/@babel/runtime/helpers/asyncToGenerator.js:21:12)

FAIL test/process-html.test.js
  ● Process HTML › Unknown tags within code tag should be stay the same

    ReferenceError: removeDevToFullscreen is not defined

      41 |   lazyLoad(dom);
      42 |   // Deal with "Enter fullscreen mode Exit fullscreen mode" text from dev.to bug
    > 43 |   removeDevToFullscreen(dom);
         |   ^
      44 |
      45 |   // Return the resulting HTML
      46 |   return dom.window.document.body.innerHTML;

      at process (src/backend/utils/html/index.js:43:3)
      at Object.<anonymous> (test/process-html.test.js:7:18)

  ● Process HTML › https://github.com/Seneca-CDOT/telescope/issues/2313

    ReferenceError: removeDevToFullscreen is not defined

      41 |   lazyLoad(dom);
      42 |   // Deal with "Enter fullscreen mode Exit fullscreen mode" text from dev.to bug
    > 43 |   removeDevToFullscreen(dom);
         |   ^
      44 |
      45 |   // Return the resulting HTML
      46 |   return dom.window.document.body.innerHTML;

      at process (src/backend/utils/html/index.js:43:3)
      at Object.<anonymous> (test/process-html.test.js:12:18)

  ● Process HTML › https://github.com/Seneca-CDOT/telescope/issues/2220

    ReferenceError: removeDevToFullscreen is not defined

      41 |   lazyLoad(dom);
      42 |   // Deal with "Enter fullscreen mode Exit fullscreen mode" text from dev.to bug
    > 43 |   removeDevToFullscreen(dom);
         |   ^
      44 |
      45 |   // Return the resulting HTML
      46 |   return dom.window.document.body.innerHTML;

      at process (src/backend/utils/html/index.js:43:3)
      at Object.<anonymous> (test/process-html.test.js:20:18)

  ● Process HTML › Double escape character stay the same

    ReferenceError: removeDevToFullscreen is not defined

      41 |   lazyLoad(dom);
      42 |   // Deal with "Enter fullscreen mode Exit fullscreen mode" text from dev.to bug
    > 43 |   removeDevToFullscreen(dom);
         |   ^
      44 |
      45 |   // Return the resulting HTML
      46 |   return dom.window.document.body.innerHTML;

      at process (src/backend/utils/html/index.js:43:3)
      at Object.<anonymous> (test/process-html.test.js:29:18)

  ● Process HTML › Escape character stay the same

    ReferenceError: removeDevToFullscreen is not defined

      41 |   lazyLoad(dom);
      42 |   // Deal with "Enter fullscreen mode Exit fullscreen mode" text from dev.to bug
    > 43 |   removeDevToFullscreen(dom);
         |   ^
      44 |
      45 |   // Return the resulting HTML
      46 |   return dom.window.document.body.innerHTML;

      at process (src/backend/utils/html/index.js:43:3)
      at Object.<anonymous> (test/process-html.test.js:35:18)

  ● Process HTML › https://github.com/Seneca-CDOT/telescope/issues/1091

    ReferenceError: removeDevToFullscreen is not defined

      41 |   lazyLoad(dom);
      42 |   // Deal with "Enter fullscreen mode Exit fullscreen mode" text from dev.to bug
    > 43 |   removeDevToFullscreen(dom);
         |   ^
      44 |
      45 |   // Return the resulting HTML
      46 |   return dom.window.document.body.innerHTML;

      at process (src/backend/utils/html/index.js:43:3)
      at Object.<anonymous> (test/process-html.test.js:41:18)

@Kevan-Y
Copy link
Contributor Author

Kevan-Y commented Oct 24, 2021

Did you rebase onto the right commit? Looks like you've got issues with removeDevToFullscreen, which I think we ripped out quite a while ago.

Summary of all failing tests
FAIL test/feed.test.js
  ● Post data class tests › Get and Set Feed objects from database › Removing feeds should also remove posts

    ReferenceError: removeDevToFullscreen is not defined

      41 |   lazyLoad(dom);
      42 |   // Deal with "Enter fullscreen mode Exit fullscreen mode" text from dev.to bug
    > 43 |   removeDevToFullscreen(dom);
         |   ^
      44 |
      45 |   // Return the resulting HTML
      46 |   return dom.window.document.body.innerHTML;

      at processHTML (src/backend/utils/html/index.js:43:3)
      at _callee$ (src/backend/data/post.js:134:14)
      at tryCatch (node_modules/regenerator-runtime/runtime.js:63:40)
      at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:294:22)
      at Generator.next (node_modules/regenerator-runtime/runtime.js:119:21)
      at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
      at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:25:9)
      at node_modules/@babel/runtime/helpers/asyncToGenerator.js:32:7
      at Function.<anonymous> (node_modules/@babel/runtime/helpers/asyncToGenerator.js:21:12)

FAIL test/post.test.js
  ● Post data class tests › Post.createFromArticle() tests › should work with real world RSS

    ReferenceError: removeDevToFullscreen is not defined

      41 |   lazyLoad(dom);
      42 |   // Deal with "Enter fullscreen mode Exit fullscreen mode" text from dev.to bug
    > 43 |   removeDevToFullscreen(dom);
         |   ^
      44 |
      45 |   // Return the resulting HTML
      46 |   return dom.window.document.body.innerHTML;

      at processHTML (src/backend/utils/html/index.js:43:3)
      at _callee$ (src/backend/data/post.js:134:14)
      at tryCatch (node_modules/regenerator-runtime/runtime.js:63:40)
      at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:294:22)
      at Generator.next (node_modules/regenerator-runtime/runtime.js:119:21)
      at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
      at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:25:9)
      at node_modules/@babel/runtime/helpers/asyncToGenerator.js:32:7
      at Function.<anonymous> (node_modules/@babel/runtime/helpers/asyncToGenerator.js:21:12)

  ● Post data class tests › Post.createFromArticle() tests › Post.createFromArticle() with missing date should not throw

    ReferenceError: removeDevToFullscreen is not defined

      41 |   lazyLoad(dom);
      42 |   // Deal with "Enter fullscreen mode Exit fullscreen mode" text from dev.to bug
    > 43 |   removeDevToFullscreen(dom);
         |   ^
      44 |
      45 |   // Return the resulting HTML
      46 |   return dom.window.document.body.innerHTML;

      at processHTML (src/backend/utils/html/index.js:43:3)
      at _callee$ (src/backend/data/post.js:134:14)
      at tryCatch (node_modules/regenerator-runtime/runtime.js:63:40)
      at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:294:22)
      at Generator.next (node_modules/regenerator-runtime/runtime.js:119:21)
      at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
      at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:25:9)
      at node_modules/@babel/runtime/helpers/asyncToGenerator.js:32:7
      at Function.<anonymous> (node_modules/@babel/runtime/helpers/asyncToGenerator.js:21:12)

  ● Post data class tests › Post.createFromArticle() tests › Post.createFromArticle() with missing title should use Untitled

    ReferenceError: removeDevToFullscreen is not defined

      41 |   lazyLoad(dom);
      42 |   // Deal with "Enter fullscreen mode Exit fullscreen mode" text from dev.to bug
    > 43 |   removeDevToFullscreen(dom);
         |   ^
      44 |
      45 |   // Return the resulting HTML
      46 |   return dom.window.document.body.innerHTML;

      at processHTML (src/backend/utils/html/index.js:43:3)
      at _callee$ (src/backend/data/post.js:134:14)
      at tryCatch (node_modules/regenerator-runtime/runtime.js:63:40)
      at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:294:22)
      at Generator.next (node_modules/regenerator-runtime/runtime.js:119:21)
      at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
      at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:25:9)
      at node_modules/@babel/runtime/helpers/asyncToGenerator.js:32:7
      at Function.<anonymous> (node_modules/@babel/runtime/helpers/asyncToGenerator.js:21:12)

FAIL test/process-html.test.js
  ● Process HTML › Unknown tags within code tag should be stay the same

    ReferenceError: removeDevToFullscreen is not defined

      41 |   lazyLoad(dom);
      42 |   // Deal with "Enter fullscreen mode Exit fullscreen mode" text from dev.to bug
    > 43 |   removeDevToFullscreen(dom);
         |   ^
      44 |
      45 |   // Return the resulting HTML
      46 |   return dom.window.document.body.innerHTML;

      at process (src/backend/utils/html/index.js:43:3)
      at Object.<anonymous> (test/process-html.test.js:7:18)

  ● Process HTML › https://github.com/Seneca-CDOT/telescope/issues/2313

    ReferenceError: removeDevToFullscreen is not defined

      41 |   lazyLoad(dom);
      42 |   // Deal with "Enter fullscreen mode Exit fullscreen mode" text from dev.to bug
    > 43 |   removeDevToFullscreen(dom);
         |   ^
      44 |
      45 |   // Return the resulting HTML
      46 |   return dom.window.document.body.innerHTML;

      at process (src/backend/utils/html/index.js:43:3)
      at Object.<anonymous> (test/process-html.test.js:12:18)

  ● Process HTML › https://github.com/Seneca-CDOT/telescope/issues/2220

    ReferenceError: removeDevToFullscreen is not defined

      41 |   lazyLoad(dom);
      42 |   // Deal with "Enter fullscreen mode Exit fullscreen mode" text from dev.to bug
    > 43 |   removeDevToFullscreen(dom);
         |   ^
      44 |
      45 |   // Return the resulting HTML
      46 |   return dom.window.document.body.innerHTML;

      at process (src/backend/utils/html/index.js:43:3)
      at Object.<anonymous> (test/process-html.test.js:20:18)

  ● Process HTML › Double escape character stay the same

    ReferenceError: removeDevToFullscreen is not defined

      41 |   lazyLoad(dom);
      42 |   // Deal with "Enter fullscreen mode Exit fullscreen mode" text from dev.to bug
    > 43 |   removeDevToFullscreen(dom);
         |   ^
      44 |
      45 |   // Return the resulting HTML
      46 |   return dom.window.document.body.innerHTML;

      at process (src/backend/utils/html/index.js:43:3)
      at Object.<anonymous> (test/process-html.test.js:29:18)

  ● Process HTML › Escape character stay the same

    ReferenceError: removeDevToFullscreen is not defined

      41 |   lazyLoad(dom);
      42 |   // Deal with "Enter fullscreen mode Exit fullscreen mode" text from dev.to bug
    > 43 |   removeDevToFullscreen(dom);
         |   ^
      44 |
      45 |   // Return the resulting HTML
      46 |   return dom.window.document.body.innerHTML;

      at process (src/backend/utils/html/index.js:43:3)
      at Object.<anonymous> (test/process-html.test.js:35:18)

  ● Process HTML › https://github.com/Seneca-CDOT/telescope/issues/1091

    ReferenceError: removeDevToFullscreen is not defined

      41 |   lazyLoad(dom);
      42 |   // Deal with "Enter fullscreen mode Exit fullscreen mode" text from dev.to bug
    > 43 |   removeDevToFullscreen(dom);
         |   ^
      44 |
      45 |   // Return the resulting HTML
      46 |   return dom.window.document.body.innerHTML;

      at process (src/backend/utils/html/index.js:43:3)
      at Object.<anonymous> (test/process-html.test.js:41:18)

Sorry about that. I fixed and ran the test. All should be good.

Copy link
Contributor

@humphd humphd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm tempted to try this and see what happens, but I'd like to think on it a bit more.

Copy link
Contributor

@humphd humphd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to approve this and we'll test/fix based on what we see on staging.

@Grommers00
Copy link
Contributor

Grommers00 commented Oct 27, 2021

Okay, so, after reading the original issue, the point of this PR is to fix up why things in a < code > tag were not previously loading in. And part of the problem before was our sanitization.

The fix is to change some of the 'problematic' values which occur inparticular & > <?

@humphd
Copy link
Contributor

humphd commented Oct 28, 2021

@Kevan-Y can give more details

@Kevan-Y
Copy link
Contributor Author

Kevan-Y commented Oct 28, 2021

@manekenpix The issue was our current sanitization decode escape character inside of a < code > tag. Those escape characters will turn into actual characters, so when we render the page, it will convert into an actual HTML tag.

The issue came from a code fix introduced here:

const result = entities.decodeHTML(codeElement.innerHTML);
return entities.decodeHTML(result);

This was to fix this issue #1091

So if we remove replace-entitie.js. It will technically fix our current issue. But will re-introduce this bug #1091. So I used another way to fix this (#1091) bug.
#1091 bug was that passing code.innerHTML to hljs.highlightAuto() is changing for example &gt; to &amp;gt;.
So to fix it having a regex at the end of


to change it back should be enough to fix that bug.

@Grommers00
Copy link
Contributor

Okay awesome.
I think we can see if run into problems down the line and re-address them as we move forward.

@Grommers00
Copy link
Contributor

If you can just rebase it onto master. So we can merge it should be good to go :).

@humphd
Copy link
Contributor

humphd commented Oct 30, 2021

OK, let's try this. @Kevan-Y we'll open further issues to tweak it when we see what happens on staging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inline block code display issue
4 participants