matrix: URIs #112
1 changed files with 2 additions and 3 deletions
use \b + negative lookahead instead of an allowlist of preceding chars
for the matrix: uri replacing this allows it to find matrix: uris wrapped in various types of parens, without having to manually specify all of the allowed preceding characters negative lookahead bans non-word characters that could be a part of an uri
commit
d7630b60f4
|
|
@ -566,7 +566,7 @@ function serialiseReplyContent(doc) {
|
||||||
function convertMatrixUris(input) {
|
function convertMatrixUris(input) {
|
||||||
// this regex is kinda broad, but i'm not really sure how to reasonably make it stricter
|
// this regex is kinda broad, but i'm not really sure how to reasonably make it stricter
|
||||||
// we run the match through the url parser anyway, so if we get a bad match, it should just fail? hopefully?
|
// we run the match through the url parser anyway, so if we get a bad match, it should just fail? hopefully?
|
||||||
return input.replace(/(^|\s|")(matrix:[^\s"]+)/gi, (match, before, uri) => {
|
return input.replace(/(?<![\/:@?#])\b(matrix:[^\s"]+)/gi, (match, uri) => {
|
||||||
// technically the url might be html-encoded, but since we're gonna splice the url back together,
|
// technically the url might be html-encoded, but since we're gonna splice the url back together,
|
||||||
// and none of the characters that might get html-encoded are actually important to us, it doesn't really matter
|
// and none of the characters that might get html-encoded are actually important to us, it doesn't really matter
|
||||||
// (most of the case it's the query string, and we just copy it over anyway)
|
// (most of the case it's the query string, and we just copy it over anyway)
|
||||||
|
|
@ -621,8 +621,7 @@ function convertMatrixUris(input) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// now splice the path back together, add the query, and we're done!
|
// now splice the path back together, add the query, and we're done!
|
||||||
// (and don't forget to add the character before the url that we might've matched)
|
return `https://matrix.to/#/${resultSegments.join("/")}${parsed.search}`
|
||||||
return `${before}https://matrix.to/#/${resultSegments.join("/")}${parsed.search}`
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue