Skip to content

Commit

Permalink
Fix off-by-one error in allCharsAreHex
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshRosen committed Jun 25, 2024
1 parent 972cf70 commit 07f0ed7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ trait SparkParserUtils {
}

def allCharsAreHex(s: String, start: Int, length: Int): Boolean = {
val end = start + length - 1
val end = start + length
var i = start
while (i < end) {
val c = s.charAt(i)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ class ParserUtilsSuite extends SparkFunSuite {
assert(unescapeSQLString("\"abc\\uxxxxa\"") == "abcuxxxxa")
assert(unescapeSQLString("\"abc\\UXXXXXXXXa\"") == "abcUXXXXXXXXa")
assert(unescapeSQLString("\"abc\\Uxxxxxxxxa\"") == "abcUxxxxxxxxa")
// Guard against off-by-one errors in the "all chars are hex" routine:
assert(unescapeSQLString("\"abc\\uAAAXa\"") == "abcuAAAXa")

// scalastyle:on nonascii
}
Expand Down

0 comments on commit 07f0ed7

Please sign in to comment.