Skip to content

Commit

Permalink
Fixes #16357: Broken test on whitespace matching and regex is invalid…
Browse files Browse the repository at this point in the history
… for multiline
  • Loading branch information
VinceMacBuche committed Dec 6, 2019
1 parent cac84e3 commit 66df06d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@

package com.normation.rudder.ncf

import java.util.regex.Pattern

import com.normation.errors.PureResult
import com.normation.errors.Unexpected

import cats.data.NonEmptyList
import com.normation.inventory.domain.Version
import com.normation.inventory.domain.AgentType
Expand Down Expand Up @@ -202,7 +203,7 @@ object Constraint {

case object NoWhiteSpace extends Constraint {
def check(value: String): CheckResult = {
if (value.matches("""^(?!\s).*(?<!\s)$""")) {
if (Pattern.compile("""^(?!\s).*(?<!\s)$""", Pattern.DOTALL).asPredicate().test(value)) {
OK
} else {
NOK(one("Must not have leading or trailing whitespaces"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,12 +408,14 @@ class TestTechniqueWriter extends Specification with ContentMatchers with Loggab
val value3 = "S"
val value4 = "ééé ```"
val value5 = "sdfsqdfsqfsdf sfhdskjhdfs jkhsdkfjhksqdhf"
val value6 = ""

Constraint.NoWhiteSpace.check(value1) must equalTo(Constraint.OK)
Constraint.NoWhiteSpace.check(value2) must equalTo(Constraint.OK)
Constraint.NoWhiteSpace.check(value3) must equalTo(Constraint.OK)
Constraint.NoWhiteSpace.check(value4) must equalTo(Constraint.OK)
Constraint.NoWhiteSpace.check(value5) must equalTo(Constraint.OK)
Constraint.NoWhiteSpace.check(value6) must equalTo(Constraint.OK)
}

"Correctly refuse text starting or ending with withspace" in {
Expand All @@ -422,14 +424,12 @@ class TestTechniqueWriter extends Specification with ContentMatchers with Loggab
""" Some
|text""".stripMargin
val value3 = " "
val value4 = ""
val value5 = "sdfsqdfsqfsdf sfhdskjhdfs jkhsdkfjhksqdhf "
val value4 = "sdfsqdfsqfsdf sfhdskjhdfs jkhsdkfjhksqdhf "

Constraint.NoWhiteSpace.check(value1) must haveClass[Constraint.NOK]
Constraint.NoWhiteSpace.check(value2) must haveClass[Constraint.NOK]
Constraint.NoWhiteSpace.check(value3) must haveClass[Constraint.NOK]
Constraint.NoWhiteSpace.check(value4) must haveClass[Constraint.NOK]
Constraint.NoWhiteSpace.check(value5) must haveClass[Constraint.NOK]
}
}

Expand Down

0 comments on commit 66df06d

Please sign in to comment.