mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-07 14:05:52 +01:00
Add escapeTaskList method, it escapse '- [] ' characters
This commit is contained in:
@@ -9,6 +9,7 @@ import org.pegdown.ast._
|
|||||||
import org.pegdown.LinkRenderer.Rendering
|
import org.pegdown.LinkRenderer.Rendering
|
||||||
import java.text.Normalizer
|
import java.text.Normalizer
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
import java.util.regex.Pattern
|
||||||
import scala.collection.JavaConverters._
|
import scala.collection.JavaConverters._
|
||||||
import service.{RequestCache, WikiService}
|
import service.{RequestCache, WikiService}
|
||||||
|
|
||||||
@@ -149,4 +150,8 @@ object GitBucketHtmlSerializer {
|
|||||||
val noSpecialChars = StringUtil.urlEncode(normalized)
|
val noSpecialChars = StringUtil.urlEncode(normalized)
|
||||||
noSpecialChars.toLowerCase(Locale.ENGLISH)
|
noSpecialChars.toLowerCase(Locale.ENGLISH)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def escapeTaskList(text: String): String = {
|
||||||
|
Pattern.compile("""^ *- \[([x| ])\] """, Pattern.MULTILINE).matcher(text).replaceAll("task:$1: ")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,4 +25,69 @@ class GitBucketHtmlSerializerSpec extends Specification {
|
|||||||
after mustEqual "foo%21bar%40baz%3e9000"
|
after mustEqual "foo%21bar%40baz%3e9000"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
"escapeTaskList" should {
|
||||||
|
"convert '- [ ] ' to 'task: :'" in {
|
||||||
|
val before = "- [ ] aaaa"
|
||||||
|
val after = escapeTaskList(before)
|
||||||
|
after mustEqual "task: : aaaa"
|
||||||
|
}
|
||||||
|
|
||||||
|
"convert ' - [ ] ' to 'task: :'" in {
|
||||||
|
val before = " - [ ] aaaa"
|
||||||
|
val after = escapeTaskList(before)
|
||||||
|
after mustEqual "task: : aaaa"
|
||||||
|
}
|
||||||
|
|
||||||
|
"convert only first '- [ ] '" in {
|
||||||
|
val before = " - [ ] aaaa - [ ] bbb"
|
||||||
|
val after = escapeTaskList(before)
|
||||||
|
after mustEqual "task: : aaaa - [ ] bbb"
|
||||||
|
}
|
||||||
|
|
||||||
|
"convert '- [x] ' to 'task: :'" in {
|
||||||
|
val before = " - [x] aaaa"
|
||||||
|
val after = escapeTaskList(before)
|
||||||
|
after mustEqual "task:x: aaaa"
|
||||||
|
}
|
||||||
|
|
||||||
|
"convert multi lines" in {
|
||||||
|
val before = """
|
||||||
|
tasks
|
||||||
|
- [x] aaaa
|
||||||
|
- [ ] bbb
|
||||||
|
"""
|
||||||
|
val after = escapeTaskList(before)
|
||||||
|
after mustEqual """
|
||||||
|
tasks
|
||||||
|
task:x: aaaa
|
||||||
|
task: : bbb
|
||||||
|
"""
|
||||||
|
}
|
||||||
|
|
||||||
|
"no convert if inserted before '- [ ] '" in {
|
||||||
|
val before = " a - [ ] aaaa"
|
||||||
|
val after = escapeTaskList(before)
|
||||||
|
after mustEqual " a - [ ] aaaa"
|
||||||
|
}
|
||||||
|
|
||||||
|
"no convert '- [] '" in {
|
||||||
|
val before = " - [] aaaa"
|
||||||
|
val after = escapeTaskList(before)
|
||||||
|
after mustEqual " - [] aaaa"
|
||||||
|
}
|
||||||
|
|
||||||
|
"no convert '- [ ]a'" in {
|
||||||
|
val before = " - [ ]a aaaa"
|
||||||
|
val after = escapeTaskList(before)
|
||||||
|
after mustEqual " - [ ]a aaaa"
|
||||||
|
}
|
||||||
|
|
||||||
|
"no convert '-[ ] '" in {
|
||||||
|
val before = " -[ ] aaaa"
|
||||||
|
val after = escapeTaskList(before)
|
||||||
|
after mustEqual " -[ ] aaaa"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user