Skip to content

Commit

Permalink
IDEA-CR-58318: TextMate: use non-strict utf-8 encoding (IDEA-232576)
Browse files Browse the repository at this point in the history
To avoid endless loop described here: jruby/joni#17

(cherry picked from commit 21619a0255e1facf7e1aaa5879ca36956b98e45a)

GitOrigin-RevId: 7c698742fa33d97047e98b7bbee9e5307844712b
  • Loading branch information
zolotov authored and intellij-monorepo-bot committed Feb 12, 2020
1 parent bf4755b commit 63d2b77
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.common.base.Preconditions;
import com.intellij.openapi.util.TextRange;
import org.jcodings.specific.NonStrictUTF8Encoding;
import org.jcodings.specific.UTF8Encoding;
import org.jetbrains.annotations.NotNull;

Expand All @@ -14,7 +15,7 @@ public static int charOffsetByByteOffset(byte[] stringBytes, int byteOffset) {
return 0;
}
Preconditions.checkPositionIndex(byteOffset, stringBytes.length);
return UTF8Encoding.INSTANCE.strLength(stringBytes, 0, byteOffset);
return NonStrictUTF8Encoding.INSTANCE.strLength(stringBytes, 0, byteOffset);
}

public static int byteOffsetByCharOffset(@NotNull CharSequence charSequence, int charOffset) {
Expand Down
1 change: 1 addition & 0 deletions plugins/textmate/testData/lexer/markdown/unknown_utf.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
## 🚧🚧🚧 UNDER CONSTRUCTION 🚧🚧🚧
4 changes: 4 additions & 0 deletions plugins/textmate/testData/lexer/markdown/unknown_utf_after.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
text.html.markdown markup.heading.${1/(#)(#)?(#)?(#)?(#)?(#)?/${6:?6:${5:?5:${4:?4:${3:?3:${2:?2:1}}}}}/}.markdown punctuation.definition.heading.markdown: [0, 2], {##}
text.html.markdown markup.heading.${1/(#)(#)?(#)?(#)?(#)?(#)?/${6:?6:${5:?5:${4:?4:${3:?3:${2:?2:1}}}}}/}.markdown: [2, 3], { }
text.html.markdown markup.heading.${1/(#)(#)?(#)?(#)?(#)?(#)?/${6:?6:${5:?5:${4:?4:${3:?3:${2:?2:1}}}}}/}.markdown entity.name.section.markdown: [3, 29], {🚧🚧🚧 UNDER CONSTRUCTION }
text.html.markdown meta.paragraph.markdown: [29, 35], {🚧🚧🚧}

0 comments on commit 63d2b77

Please sign in to comment.