Skip to content

Commit

Permalink
fix(ParserJS): fix reading flags when multiple flags are passed (#176)
Browse files Browse the repository at this point in the history
  • Loading branch information
hugo-vrijswijk authored Jul 26, 2022
1 parent ffd8874 commit 9abdbc4
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion core/src/main/scala/weaponregex/parser/ParserJS.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import weaponregex.model.regextree.*
class ParserJS private[parser] (pattern: String, val flags: Option[String] = None) extends Parser(pattern) {

/** Whether the flags contain the `u` flag for Unicode mode */
private val unicodeMode: Boolean = flags.contains("u")
private val unicodeMode: Boolean = flags.exists(_.contains("u"))

/** Regex special characters
*/
Expand Down
4 changes: 3 additions & 1 deletion core/src/main/scalajs/weaponregex/WeaponRegeXJS.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ object WeaponRegeXJS {
if (options.hasOwnProperty("flavor") && options.flavor != null) options.flavor
else ParserFlavorJS

Parser(pattern, flags.toOption, flavor) match {
val flagsOpt = flags.toOption.filterNot(_ == null).filterNot(_.isEmpty)

Parser(pattern, flagsOpt, flavor) match {
case Right(tree) => (tree.mutate(mutators, mutationLevels) map MutantJS).toJSArray
case Left(msg) => throw new RuntimeException(msg)
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/test/scala/weaponregex/parser/ParserJSTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class ParserJSTest extends munit.FunSuite with ParserTest {

test("Parse `\\u{20}` as Unicode character with the Unicode flag") {
val pattern = "\\u{20}"
val parsedTree = Parser(pattern, Some("u"), parserFlavor).getOrFail.to[MetaChar]
val parsedTree = Parser(pattern, Some("ug"), parserFlavor).getOrFail.to[MetaChar]

assertEquals(parsedTree.metaChar, "u{20}")

Expand Down

0 comments on commit 9abdbc4

Please sign in to comment.