Skip to content

Commit

Permalink
Fix unescapeHTML also for JRuby
Browse files Browse the repository at this point in the history
  • Loading branch information
flosacca committed Nov 28, 2023
1 parent 67610e6 commit 354a408
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions ext/java/org/jruby/ext/cgi/escape/CGIEscape.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ static boolean MATCH(byte[] s, int len, int i, byte[] cstrBytes, int cstr) {
int charlimit = (enc instanceof UTF8Encoding) ? UNICODE_MAX :
(enc instanceof ISO8859_1Encoding) ? 256 :
128;
int i, len, beg = 0;
int i, j, len, beg = 0;
int clen = 0, plen;
boolean overflow = false;
byte[] cstrBytes;
Expand All @@ -160,6 +160,7 @@ static boolean MATCH(byte[] s, int len, int i, byte[] cstrBytes, int cstr) {
plen = i - beg;
if (++i >= len) break;
c = cstrBytes[cstr + i] & 0xFF;
j = i;
switch (c) {
case 'a':
++i;
Expand All @@ -169,28 +170,40 @@ static boolean MATCH(byte[] s, int len, int i, byte[] cstrBytes, int cstr) {
} else if (MATCH(MPSEMI, len, i, cstrBytes, cstr)) {
i += MPSEMI.length - 1;
c = '&';
} else continue;
} else {
i = j;
continue;
}
break;
case 'q':
++i;
if (MATCH(UOTSEMI, len, i, cstrBytes, cstr)) {
i += UOTSEMI.length - 1;
c = '"';
} else continue;
} else {
i = j;
continue;
}
break;
case 'g':
++i;
if (MATCH(TSEMI, len, i, cstrBytes, cstr)) {
i += TSEMI.length - 1;
c = '>';
} else continue;
} else {
i = j;
continue;
}
break;
case 'l':
++i;
if (MATCH(TSEMI, len, i, cstrBytes, cstr)) {
i += TSEMI.length - 1;
c = '<';
} else continue;
} else {
i = j;
continue;
}
break;
case '#':
if (len - ++i >= 2 && Character.isDigit(cstrBytes[cstr + i])) {
Expand All @@ -203,9 +216,15 @@ static boolean MATCH(byte[] s, int len, int i, byte[] cstrBytes, int cstr) {
cc = ruby_scan_digits(cstrBytes, cstr + i, len - i, 16, clenOverflow);
clen = clenOverflow[0];
overflow = clenOverflow[1] == 1;
} else continue;
} else {
i = j;
continue;
}
i += clen;
if (overflow || cc >= charlimit || i >= len || cstrBytes[cstr + i] != ';') continue;
if (overflow || cc >= charlimit || i >= len || cstrBytes[cstr + i] != ';') {
i = j;
continue;
}
if (dest == null) {
dest = RubyString.newStringLight(runtime, len);
}
Expand Down

0 comments on commit 354a408

Please sign in to comment.