w8tcha / CKEditor-TextSelection-Plugin

The plugin that makes the editor keep it's text-selection when switching between WYSIWYG and Source mode, and scrolls the selection into the viewport.
MIT License
10 stars 7 forks source link

decodeURIComponent fails if source text contains % #18

Closed dm0 closed 9 years ago

dm0 commented 9 years ago

the following sample (source) causes decodeURIComponent failure.

<style type="text/css">.rule {
  width: 50%;
}
  .r2{
    width: 50%;
  }
</style>
<div>content</div>
w8tcha commented 9 years ago

Can you describe the steps to reproduce the problem and also post you editor config?

dm0 commented 9 years ago

I believe editor config is not important. Steps to reproduce: Add following code to the top of page source on demo page (http://w8tcha.github.io/CKEditor-TextSelection-Plugin/demoCodeMirror.html):

<style type="text/css">
.someClass {
  width: 100%;
}
</style>

Leave text cursor inside style tag (i.e. put it after semicolon). Switch to wysiwyg mode.

Error reported by browser is not always accurate, but failing call is: decodeURIComponent(startNode.$.nodeValue)

Reason - nodeValue of style tag doesn't contain valid URL-enoded data (it has percent sign followed by semicolon)

dm0 commented 9 years ago

I have a fix for this problem in my fork, but it is not well-tested yet, so i'm not sure if everything is ok.

fork is here: https://github.com/dm0/CKEditor-TextSelection-Plugin

Also in my fix I attempted to resolve problem of empty lines addition to source code of style and script tags.

w8tcha commented 9 years ago

Thanks now i was able to reproduce the issue, but you fix attempt doesn't seem to work.

I replaced decodeURIComponent with unescape and now it seem to work