Skip to content

Commit c3b38e0

Browse files
committed
Made decreasing ranges inside character classes illegal to comply with Java/JS regex standards.
1 parent 4a361da commit c3b38e0

3 files changed

Lines changed: 9 additions & 13 deletions

File tree

core/src/main/kotlin/org/evomaster/core/utils/CharacterRange.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package org.evomaster.core.utils
22

3-
class CharacterRange private constructor(val start: Char, val end: Char){
4-
companion object {
5-
operator fun invoke(a: Char, b: Char): CharacterRange =
6-
if (a <= b) CharacterRange(a, b) else CharacterRange(b, a)
7-
}
8-
3+
class CharacterRange constructor(val start: Char, val end: Char){
94
constructor(a: Int, b: Int) : this(a.toChar(), b.toChar())
105

6+
init {
7+
if (start > end){
8+
throw IllegalArgumentException("Range out of order in character class")
9+
}
10+
}
11+
1112
val size: Int
1213
get() = end.code - start.code + 1
1314
operator fun contains(char: Char): Boolean = char in start..end

core/src/test/kotlin/org/evomaster/core/parser/GeneRegexJavaVisitorTest.kt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,6 @@ class GeneRegexJavaVisitorTest : GeneRegexEcma262VisitorTest() {
6666
checkSameAsJava("[ -!]")
6767
}
6868

69-
@Test
70-
fun testDecreasingRange(){
71-
//checkSameAsJava("[!- ]") //not valid in Java
72-
//checkSameAsJava("[9-1]") //not valid in Java
73-
checkCanSample("[9-1]", listOf("1","5","9"),200)
74-
}
75-
7669
@Test
7770
fun testJavaHexEscape(){
7871
checkSameAsJava("""x{3}\x{0}\x{FFFf}\x{0FFFf}\x{01FFFf}\x{10FFFf}""")

core/src/test/kotlin/org/evomaster/core/parser/RegexHandlerTest.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,14 @@ internal class RegexHandlerTest{
160160
assertThrows(IllegalArgumentException::class.java) { RegexHandler.createGeneForJVM("\\x{ffffff}") }
161161
assertThrows(ParseCancellationException::class.java) { RegexHandler.createGeneForJVM("\\0") }
162162
assertThrows(ParseCancellationException::class.java) { RegexHandler.createGeneForJVM("\\09") }
163+
assertThrows(IllegalArgumentException::class.java) { RegexHandler.createGeneForJVM("[9-1]") }
163164
}
164165

165166
@Test
166167
fun testCreateGeneForEcma262InvalidRegex() {
167168

168169
assertThrows(ParseCancellationException::class.java) { RegexHandler.createGeneForEcma262("\\xR") }
169170
assertThrows(ParseCancellationException::class.java) { RegexHandler.createGeneForJVM("\\ugggg") }
171+
assertThrows(IllegalArgumentException::class.java) { RegexHandler.createGeneForJVM("[9-1]") }
170172
}
171173
}

0 commit comments

Comments
 (0)