Skip to content

Commit

Permalink
Merge pull request #1799 from NationalSecurityAgency/t#1797/newline_bug
Browse files Browse the repository at this point in the history
#1797 - need to make regex for replacing linebreaks and separators wi…
  • Loading branch information
sudo-may authored Nov 9, 2022
2 parents b6cd07e + 56bb1c6 commit 8054e8a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
8 changes: 6 additions & 2 deletions service/src/main/java/skills/services/CustomValidator.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ class CustomValidator {
// split if
// - there is at least 2 new lines
// - markdown separator (3 underscores, 3 dashes, 3 stars)
String[] paragraphs = preProcessForMarkdownSupport(description).split("([\n]{2,})|(\n[\\s]*[-_*]{3,})")
description = preProcessForMarkdownSupport(description)
if (StringUtils.isBlank(description)) {
return new CustomValidationResult(valid: true)
}
String[] paragraphs = description.split("([\n]{2,})|(\n[\\s]*[-_*]{3,})")

CustomValidationResult validationResult = null
for (String s : paragraphs) {
Expand All @@ -139,7 +143,7 @@ class CustomValidator {
// String toValidate = s.trim()

// treat all linebreaks and separators as newlines
toValidate = toValidate.replaceAll(/(\n\s*[-_*]{3,}^)|(\n<br>)/, '\n')
toValidate = toValidate.replaceAll(/(?m)(^\s*[-_*]{3,}\s*$)|(^\s*<br>\s*$)/, '\n')

// remove a single new line above a table and/or codeblock
toValidate = TABLE_FIX.matcher(toValidate).replaceAll('$2')
Expand Down
39 changes: 39 additions & 0 deletions service/src/test/java/skills/services/CustomValidatorSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,45 @@ A new sentence after a few new lines
A Separate me
***
no go""").valid

validator.validateDescription("""A Separate me
___
A Separate me
---
A Separate me
***
___
A Separate me
---
A Separate me
***
A
```
if (a == true) {
println 'Hello <br> <br /> World'
}
```
<br>
<br>
<br>
<br>
A new sentence after a few new lines
```""").valid

validator.validateDescription("""A this is text\n\nA\n\n***\n\n<br>\n""").valid
validator.validateDescription("""***""").valid
}

def "markdown Blockquotes should be considered during validation"() {
Expand Down

0 comments on commit 8054e8a

Please sign in to comment.