Skip to content

Commit

Permalink
Handle % in links
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacl committed Aug 11, 2018
1 parent f4aafea commit eed418d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions modules/common/src/main/base/RawHtml.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ final object RawHtml {
"""(?i)\b[a-z](?>""" + // pull out first char for perf.
"""ttp(?<=http)s?://(\w[-\w.~!$&';=:@]{0,100})|""" + // http(s) links
"""(?<![/@.-].)(?:\w{1,15}+\.){1,3}(?>com|org|edu))""" + // "lichess.org", etc
"""([/?#][-–—\w/.~!$&'()*+,;=:#?@]{0,300}+)?""" + // path, params
"""(?![\w/~$&*+=#@])""" // neg lookahead
"""([/?#][-–—\w/.~!$&'()*+,;=:#?@%]{0,300}+)?""" + // path, params
"""(?![\w/~$&*+=#@%])""" // neg lookahead
).r.pattern

private[this] val USER_LINK = """/@/([\w-]{2,30}+)?""".r
Expand Down
4 changes: 4 additions & 0 deletions modules/common/src/test/RawHtmlTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ class RawHtmlTest extends Specification {
addLinks("@foo") must_== """<a href="/@/foo">@foo</a>"""
}

"handle weird characters" in {
addLinks("lichess.org/-–%20") must_== """<a href="/-–%20">lichess.org/-–%20</a>"""
}

"handle trailing punctuation" in {
addLinks("lichess.org.") must_== """<a href="/">lichess.org</a>."""
addLinks("lichess.org)") must_== """<a href="/">lichess.org</a>)"""
Expand Down

0 comments on commit eed418d

Please sign in to comment.