Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #16357: Broken test on whitespace matching and regex is invalid for multiline #2661

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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