Skip to content

Commit

Permalink
Fix an array indexing bug when case-normalizing attributes
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 690845649
  • Loading branch information
lukesandberg authored and copybara-github committed Oct 29, 2024
1 parent f886504 commit e8315b7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ private static String consumeAttributeName(String content, int position, int len
// passes in the common case of no upper case characters.
char[] chars = new char[position - start];
content.getChars(start, position, chars, 0);
for (int i = upperCaseStartPos; i < position; i++) {
for (int i = 0; i < chars.length; i++) {
chars[i] = Ascii.toLowerCase(chars[i]);
}
return String.valueOf(chars);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,12 @@ public void testParseAttributes() {
assertThat(parseAttributes("a='\"b'")).containsExactly("a", "&quot;b");
}

@Test
public void testParseAttributes_withUppercase() {
assertThat(parseAttributes("CLASS=foo viewBox='1 2 3 4'"))
.isEqualTo(ImmutableMap.of("class", "foo", "viewbox", "1 2 3 4"));
}

@Test
public void testParseAttributes_errors() {
assertThrows(IllegalArgumentException.class, () -> parseAttributes("a="));
Expand Down

0 comments on commit e8315b7

Please sign in to comment.