Skip to content

Commit 39df946

Browse files
committed
also check with multi-byte languages
1 parent 3368ae2 commit 39df946

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

app/services/import/jira_wiki_markup/parser.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ def followed_by_word?(text, close_idx)
535535
def scan_subscript(scanner, buffer, nodes)
536536
return unless scanner.rest[0] == "~"
537537

538-
scanned = scanner.string[0...scanner.pos]
538+
scanned = scanner.string.byteslice(0, scanner.pos)
539539
return if (scanned + buffer).end_with?("~")
540540

541541
inner = extract_subscript_content(scanner)

spec/services/import/jira_wiki_markup_converter_spec.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,38 @@
304304
expect(described_class.new("*éé* and _öü_").convert)
305305
.to eq("**éé** and *öü*")
306306
end
307+
308+
it "handles Arabic inside bold" do
309+
expect(described_class.new("*مرحبا*").convert).to eq("**مرحبا**")
310+
end
311+
312+
it "handles Chinese inside bold" do
313+
expect(described_class.new("*你好*").convert).to eq("**你好**")
314+
end
315+
316+
it "handles Japanese inside italic" do
317+
expect(described_class.new("_日本語_").convert).to eq("*日本語*")
318+
end
319+
320+
it "handles Cyrillic inside bold" do
321+
expect(described_class.new("*Привет*").convert).to eq("**Привет**")
322+
end
323+
324+
it "handles Hebrew inside bold" do
325+
expect(described_class.new("*שלום*").convert).to eq("**שלום**")
326+
end
327+
328+
it "handles 4-byte emoji inside bold" do
329+
expect(described_class.new("*🎉*").convert).to eq("**🎉**")
330+
end
331+
332+
it "handles subscript after a macro preceded by a multi-byte character" do
333+
# Regression: scanner.string[0...scanner.pos] mixed byte-pos with char-slicing,
334+
# causing "é*x*~2~" to spuriously "see" the closing ~ in the already-scanned
335+
# prefix and skip subscript parsing.
336+
expect(described_class.new("é*x*~2~").convert).to eq("é**x**<sub>2</sub>")
337+
expect(described_class.new("🎉*x*~2~").convert).to eq("🎉**x**<sub>2</sub>")
338+
end
307339
end
308340
end
309341

0 commit comments

Comments
 (0)