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 | 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><!-- <em>Some Text</em> --></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)
#3
@
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><!-- <em>Some Text</em> –></code>
wptexturize seems to be slightly flawed in the terms of HTML within code blocks:
in:
<code><!-- <em>Some Text</em> --></code><br /> <code><!-- TEST --></code>
out:
<code><!-- <em>Some Text</em> –></code><br /> <code><!-- TEST --></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 '<!-- ' (length=8) 3 => string '<em>' (length=4) 4 => string 'Some Text' (length=9) 5 => string '</em>' (length=5) 6 => string ' -->' (length=7) 7 => string '</code>' (length=7) 8 => string ' &' (length=2) 9 => string '<code>' (length=6) 10 => string '<!-- TEST -->' (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><!-- <em>Some Text</em> --></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>‘); </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)
Uh, uh, wait... I'm not using the VISUAL editor. I'm using the Code Editor.