Fix parsing non-ascii tags
This commit is contained in:
parent
510392e4ca
commit
0b0b1dabdf
|
@ -0,0 +1 @@
|
||||||
|
Fix parsing non-ascii tags
|
|
@ -14,8 +14,11 @@ export const mentionMatchesUrl = (attention, url) => {
|
||||||
* @param {string} url
|
* @param {string} url
|
||||||
*/
|
*/
|
||||||
export const extractTagFromUrl = (url) => {
|
export const extractTagFromUrl = (url) => {
|
||||||
const regex = /tag[s]*\/(\w+)$/g
|
const decoded = decodeURI(url)
|
||||||
const result = regex.exec(url)
|
// https://git.pleroma.social/pleroma/elixir-libraries/linkify/-/blob/master/lib/linkify/parser.ex
|
||||||
|
// https://www.pcre.org/original/doc/html/pcrepattern.html
|
||||||
|
const regex = /tag[s]*\/([\p{L}\p{N}_]*[\p{Alphabetic}_·\u{200c}][\p{L}\p{N}_·\p{M}\u{200c}]*)$/ug
|
||||||
|
const result = regex.exec(decoded)
|
||||||
if (!result) {
|
if (!result) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,5 +78,11 @@ describe('MatcherService', () => {
|
||||||
|
|
||||||
expect(MatcherService.extractTagFromUrl(url)).to.eql(false)
|
expect(MatcherService.extractTagFromUrl(url)).to.eql(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should return tag name from non-ascii tags', () => {
|
||||||
|
const url = encodeURI('https://website.com/tag/喵喵喵')
|
||||||
|
|
||||||
|
expect(MatcherService.extractTagFromUrl(url)).to.eql('喵喵喵')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue