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) {
|
} else if (span instanceof RubySpan) {
|
||||||
RubySpan rubySpan = (RubySpan) span;
|
RubySpan rubySpan = (RubySpan) span;
|
||||||
return "<rt>" + rubySpan.rubyText + "</rt></ruby>";
|
return "<rt>" + escapeHtml(rubySpan.rubyText) + "</rt></ruby>";
|
||||||
} else if (span instanceof UnderlineSpan) {
|
} else if (span instanceof UnderlineSpan) {
|
||||||
return "</u>";
|
return "</u>";
|
||||||
}
|
}
|
||||||
|
@ -95,38 +95,35 @@ public class SpannedToHtmlConverterTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void convert_supportsRubySpan_over() {
|
public void convert_supportsRubySpan() {
|
||||||
SpannableString spanned = new SpannableString("String with over-annotated section");
|
SpannableString spanned =
|
||||||
|
new SpannableString("String with over-annotated and under-annotated section");
|
||||||
spanned.setSpan(
|
spanned.setSpan(
|
||||||
new RubySpan("ruby-text", RubySpan.POSITION_OVER),
|
new RubySpan("ruby-text", RubySpan.POSITION_OVER),
|
||||||
"String with ".length(),
|
"String with ".length(),
|
||||||
"String with over-annotated".length(),
|
"String with over-annotated".length(),
|
||||||
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
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(
|
spanned.setSpan(
|
||||||
new RubySpan("ruby-text", RubySpan.POSITION_UNDER),
|
new RubySpan("non-àscìì-text", RubySpan.POSITION_UNDER),
|
||||||
"String with ".length(),
|
"String with over-annotated and ".length(),
|
||||||
"String with under-annotated".length(),
|
"String with over-annotated and under-annotated".length(),
|
||||||
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
|
|
||||||
String html = SpannedToHtmlConverter.convert(spanned);
|
String html = SpannedToHtmlConverter.convert(spanned);
|
||||||
|
|
||||||
assertThat(html)
|
assertThat(html)
|
||||||
.isEqualTo(
|
.isEqualTo(
|
||||||
"String with"
|
"String with "
|
||||||
+ " <ruby style='ruby-position:under;'>under-annotated<rt>ruby-text</rt></ruby>"
|
+ "<ruby style='ruby-position:over;'>"
|
||||||
+ " section");
|
+ "over-annotated"
|
||||||
|
+ "<rt>ruby-text</rt>"
|
||||||
|
+ "</ruby> "
|
||||||
|
+ "and "
|
||||||
|
+ "<ruby style='ruby-position:under;'>"
|
||||||
|
+ "under-annotated"
|
||||||
|
+ "<rt>non-àscìì-text</rt>"
|
||||||
|
+ "</ruby> "
|
||||||
|
+ "section");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
x
Reference in New Issue
Block a user