ssbc / ssb-ref

check if a string is a valid ssb-reference
MIT License
14 stars 10 forks source link

fix extract on non encoded urls when ID starts with number #17

Closed mmckegg closed 6 years ago

mmckegg commented 6 years ago

extract attempts to perform a decodeURIComponent on a URL before running the ref regexp against it.

The problem is that sometimes IDs can be URL decoded even when they were not encoded in the first place (e.g. ID starts with a number %09Vq6Fa0zhyq9KH6dYMc/g17L04jDbl1py8arGQmL1I=.sha256 becomes \tVq6Fa0zhyq9KH6dYMc/g17L04jDbl1py8arGQmL1I=.sha256).

This means that these URLs are not detected as links.

This PR fixes the bug by first checking to see if the URL matches the regexp before URL decoding. All tests pass.

Merging in 3, 2 ...

mmckegg commented 6 years ago

Published as ssb-ref@2.11.1