Make WordPress Core

Opened 2 years ago

Last modified 2 years ago

#56893 new defect (bug)

Unnecessary line breaks added by the code editor that breaks JavaScript

Reported by: sweetheatmn's profile sweetheatmn Owned by:
Milestone: Awaiting Review Priority: normal
Severity: critical Version: 6.0.3
Component: Editor Keywords:
Focuses: Cc:

Description (last modified by sabernhardt)

adding a simple JavaScript to the code editor and hitting the publish button just adds unnecessary

<br />

inside the Javascript which is a sufficient reason to break any JavaScript

How to reproduce: simply add a new post, paste/write any JavaScript and click the publish button to see the black magic

https://i.imgur.com/fyrAwtI.png

Regards,
Atef

Change History (6)

#1 @sweetheatmn
2 years ago

+ if we add JS to the Classic Editor to bypass this issue, it still filter the content to add unnecessary

<p>

and

<br>

tags on the front-end

#2 @SergeyBiryukov
2 years ago

  • Component changed from General to Editor

#3 follow-up: @sajjad67
2 years ago

Thank You for noticing it @sweetheatmn. But the editor is not the best place to put Inline JS Code, and that's why it was not designed to escape the inline JS!! But it should escape!! I agree. @SergeyBiryukov What is your thought? Do we add an escape for the editors if it's wrapped around <script></script>

#4 in reply to: ↑ 3 @sweetheatmn
2 years ago

Replying to sajjad67:

Thank You for noticing it @sweetheatmn. But the editor is not the best place to put Inline JS Code, and that's why it was not designed to escape the inline JS!! But it should escape!! I agree. @SergeyBiryukov What is your thought? Do we add an escape for the editors if it's wrapped around <script></script>

You are welcome, This is a glitch and has to be sorted asap, JS is everywhere in embed codes and there is no logic in breaking an existing JS code

This also has to be sorted on the function that filters the content and add unnecessary paragraph tags

#5 @sajjad67
2 years ago

Yes... Let's have one of other's opinion on it. I am working on the escaping to apply. Let's see!!

#6 @sabernhardt
2 years ago

  • Description modified (diff)

The automated paragraph bug with scripts in Classic Editor is very old: #2833.

In the block editor, script tags in a paragraph block would behave similarly. However, content within a Custom HTML block should not get the inappropriate tags. Creating that block is easier in Visual mode, but in Code view you could wrap scripts in the wp:html block comments:

<!-- wp:html -->
<script>
console.log('this');
</script>
<!-- /wp:html -->
Note: See TracTickets for help on using tickets.