Escape the rubyText when generating HTML
This should have been done before, I just missed it. PiperOrigin-RevId: 304612519
This commit is contained in:
parent
bdffab1200
commit
a6358dc7be
@ -174,7 +174,7 @@ import java.util.regex.Pattern;
|
||||
}
|
||||
} else if (span instanceof RubySpan) {
|
||||
RubySpan rubySpan = (RubySpan) span;
|
||||
return "<rt>" + rubySpan.rubyText + "</rt></ruby>";
|
||||
return "<rt>" + escapeHtml(rubySpan.rubyText) + "</rt></ruby>";
|
||||
} else if (span instanceof UnderlineSpan) {
|
||||
return "</u>";
|
||||
}
|
||||
|
@ -95,29 +95,18 @@ public class SpannedToHtmlConverterTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convert_supportsRubySpan_over() {
|
||||
SpannableString spanned = new SpannableString("String with over-annotated section");
|
||||
public void convert_supportsRubySpan() {
|
||||
SpannableString spanned =
|
||||
new SpannableString("String with over-annotated and under-annotated section");
|
||||
spanned.setSpan(
|
||||
new RubySpan("ruby-text", RubySpan.POSITION_OVER),
|
||||
"String with ".length(),
|
||||
"String with over-annotated".length(),
|
||||
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
|
||||
String html = SpannedToHtmlConverter.convert(spanned);
|
||||
|
||||
assertThat(html)
|
||||
.isEqualTo(
|
||||
"String with <ruby style='ruby-position:over;'>over-annotated<rt>ruby-text</rt></ruby>"
|
||||
+ " section");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convert_supportsRubySpan_under() {
|
||||
SpannableString spanned = new SpannableString("String with under-annotated section");
|
||||
spanned.setSpan(
|
||||
new RubySpan("ruby-text", RubySpan.POSITION_UNDER),
|
||||
"String with ".length(),
|
||||
"String with under-annotated".length(),
|
||||
new RubySpan("non-àscìì-text", RubySpan.POSITION_UNDER),
|
||||
"String with over-annotated and ".length(),
|
||||
"String with over-annotated and under-annotated".length(),
|
||||
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
|
||||
String html = SpannedToHtmlConverter.convert(spanned);
|
||||
@ -125,7 +114,15 @@ public class SpannedToHtmlConverterTest {
|
||||
assertThat(html)
|
||||
.isEqualTo(
|
||||
"String with "
|
||||
+ " <ruby style='ruby-position:under;'>under-annotated<rt>ruby-text</rt></ruby>"
|
||||
+ "<ruby style='ruby-position:over;'>"
|
||||
+ "over-annotated"
|
||||
+ "<rt>ruby-text</rt>"
|
||||
+ "</ruby> "
|
||||
+ "and "
|
||||
+ "<ruby style='ruby-position:under;'>"
|
||||
+ "under-annotated"
|
||||
+ "<rt>non-àscìì-text</rt>"
|
||||
+ "</ruby> "
|
||||
+ "section");
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user