Make WordPress Core

Opened 17 years ago

Closed 17 years ago

#5073 closed defect (bug) (duplicate)

Editor behaves strange when trying to type a html comment.

Reported by: znuff's profile znuff Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.3
Component: General Keywords:
Focuses: Cc:

Description

Sorry for the poor naming, but I couldn't figure out a smarter name. Anyway, try posting the following:

<code>&lt;!-- <em>Some Text</em> --&gt;</code>

The result should be:

<code><!-- <em>Some Text</em> --></code>, but instead, wordpress spits out:

<code><!-- <em>Some Text</em> -></code>. Notice the missing dash.

Tried on Wordpress 2.3, several installs, didn't try it on previous versions.

Change History (6)

#1 @thee17
17 years ago

  • Component changed from General to TinyMCE

#2 @znuff
17 years ago

Uh, uh, wait... I'm not using the VISUAL editor. I'm using the Code Editor.

#3 @DD32
17 years ago

  • Component changed from TinyMCE to General

That'll be coming from wptexturize()

The actual HTML output of the above code is:

<code>&lt;!-- <em>Some Text</em> &#8211;&gt;</code>

wptexturize seems to be slightly flawed in the terms of HTML within code blocks:

in:

<code>&lt;!-- <em>Some Text</em> --&gt;</code><br />
<code>&lt;!-- TEST --&gt;</code>

out:

<code>&lt;!-- <em>Some Text</em> &#8211;&gt;</code><br />
<code>&lt;!-- TEST --&gt;</code>

I would've expected that within the code block, that the HTML would be escaped so as to apear to the end user rather than being presented, But thats what causes this issue:

$textarr:
array
  0 => string '' (length=0)
  1 => string '<code>' (length=6)
  2 => string '&lt;!-- ' (length=8)
  3 => string '<em>' (length=4)
  4 => string 'Some Text' (length=9)
  5 => string '</em>' (length=5)
  6 => string ' --&gt;' (length=7)
  7 => string '</code>' (length=7)
  8 => string '
&' (length=2)
  9 => string '<code>' (length=6)
  10 => string '&lt;!-- TEST --&gt;' (length=19)
  11 => string '</code>' (length=7)
  12 => string '' (length=0)

Since <code is in #1 then the "static_characters" dont get replaced, however, that flag is reset for the next array item, which causes the following lines to be texturized.

In the 2nd example i put in, due to the spliting method, and there being no unconverted HTML in the code block, it passes through A-OK as all the content of the codeblock apear in the same array item (Ie. its skipped because the preceeding item is the start of a code block)

Had the OP been using the Visual editor, then i doubt there would be a issue as TinyMCE would be encoding the HTML for him.

Just thinking about it, Perhaps all HTML within a Code block can safely be assumed that it is encoded, and as such, its a null issue?
The OP has encoded some of the content (The <!-- pieces, just not the <em>).

If the input was changed to: (as TinyMCE would do)

<code>&lt;!-- &lt;em&gt;Some Text&lt;/em&gt; --&gt;</code>

Then it works fine.

However, Running code such as this through wptexturize would cause havvoc:

<script>
alert('This is a <em>Test</em>');
</script>

produces:

<script>
alert(\'This is a <em>Test</em>&#8216;);
</script>

I'm thinking outloud here, and hopefully will bring some thoughts to mind.

znuff, Maybe your best bet is to just use a plugin thats designed to post Sourcecode into your blog? Eg. http://wordpress.org/extend/plugins/syntaxhighlighter/

(Removing TinyMCE as it has nothing to do with it)

#4 @foolswisdom
17 years ago

  • Milestone changed from 2.3.1 to 2.5

#5 @znuff
17 years ago

Uh, I didn't exactly wanted to post source code. I wanted that <em> to be parsed by the browser! If I wanted the world to see <em> I would have used &lt;em&gt;, but this was not the case. I wanted to emphase that part _inside_ the code block.

#6 @Nazgul
17 years ago

  • Milestone 2.5 deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Dupe of #3603.

Note: See TracTickets for help on using tickets.