mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
Make hashtag links URL safe
This commit is contained in:
parent
bd0273f071
commit
82d5ac99df
@ -20,7 +20,7 @@ export default function(content) {
|
||||
.get()
|
||||
const hashtags = []
|
||||
urls.forEach(url => {
|
||||
const match = exec(url, regX)
|
||||
const match = exec(decodeURI(url), regX)
|
||||
if (match != null) {
|
||||
hashtags.push(match[1])
|
||||
}
|
||||
|
||||
@ -27,14 +27,14 @@ describe('extractHashtags', () => {
|
||||
expect(extractHashtags(content)).toEqual(['Democracy'])
|
||||
})
|
||||
|
||||
it('ignores Hashtag links with not allowed character combinations', () => {
|
||||
it('ignores Hashtag links with not allowed character combinations and handles `encodeURI` URLs', () => {
|
||||
// Allowed are all unicode letters '\pL' and all digits '0-9'. There haveto be at least one letter in it.
|
||||
const content =
|
||||
'<p>Something inspirational about <a href="/search/hashtag/AbcDefXyz0123456789!*(),2" class="hashtag" target="_blank">#AbcDefXyz0123456789!*(),2</a>, <a href="/search/hashtag/0123456789" class="hashtag" target="_blank">#0123456789</a>, <a href="/search/hashtag/0123456789a" class="hashtag" target="_blank">#0123456789a</a>, <a href="/search/hashtag/AbcDefXyz0123456789" target="_blank">#AbcDefXyz0123456789</a>, and <a href="/search/hashtag/λαπ" target="_blank">#λαπ</a>.</p>'
|
||||
'<p>Something inspirational about <a href="/search/hashtag/AbcDefXyz0123456789!*(),2" class="hashtag" target="_blank">#AbcDefXyz0123456789!*(),2</a>, <a href="/search/hashtag/0123456789" class="hashtag" target="_blank">#0123456789</a>, <a href="/search/hashtag/0123456789a" class="hashtag" target="_blank">#0123456789a</a>, <a href="/search/hashtag/AbcDefXyz0123456789" target="_blank">#AbcDefXyz0123456789</a>, and <a href="/search/hashtag/%C4%A7%CF%80%CE%B1%CE%BB" target="_blank">#ħπαλ</a>.</p>'
|
||||
expect(extractHashtags(content).sort()).toEqual([
|
||||
'0123456789a',
|
||||
'AbcDefXyz0123456789',
|
||||
'λαπ',
|
||||
'ħπαλ',
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
@ -129,8 +129,8 @@ describe('hashtags', () => {
|
||||
)
|
||||
})
|
||||
|
||||
describe('afterwards update the Post by removing a Hashtag, leaving a Hashtag and add a Hashtag', () => {
|
||||
// The already existing Hashtag has no class at this point.
|
||||
describe('afterwards update the Post by removing a hashtag, leaving a hashtag and add a hashtag', () => {
|
||||
// The already existing hashtag has no class at this point.
|
||||
const postContent =
|
||||
'<p>Hey Dude, <a class="hashtag" href="/search/hashtag/Elections">#Elections</a> should work equal for everybody!? That seems to be the only way to have equal <a href="/search/hashtag/Liberty">#Liberty</a> for everyone.</p>'
|
||||
|
||||
|
||||
@ -25,7 +25,7 @@ export default class Hashtag extends TipTapMention {
|
||||
'a',
|
||||
{
|
||||
class: this.options.mentionClass,
|
||||
href: `/search/hashtag/${node.attrs.id}`,
|
||||
href: `/search/hashtag/${encodeURI(node.attrs.id)}`,
|
||||
'data-hashtag-id': node.attrs.id,
|
||||
target: '_blank',
|
||||
},
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
{{ scope.index + 1 }}.
|
||||
</template>
|
||||
<template slot="id" slot-scope="scope">
|
||||
<nuxt-link :to="{ path: '/', query: { hashtag: scope.row.id } }">
|
||||
<nuxt-link :to="{ path: '/', query: { hashtag: encodeURI(scope.row.id) } }">
|
||||
<b>#{{ scope.row.id | truncate(20) }}</b>
|
||||
</nuxt-link>
|
||||
</template>
|
||||
|
||||
@ -75,7 +75,8 @@ export default {
|
||||
MasonryGridItem,
|
||||
},
|
||||
data() {
|
||||
const { hashtag = null } = this.$route.query
|
||||
let { hashtag = null } = this.$route.query
|
||||
hashtag = decodeURI(hashtag)
|
||||
return {
|
||||
posts: [],
|
||||
hasMore: true,
|
||||
|
||||
@ -5,8 +5,9 @@
|
||||
<script>
|
||||
export default {
|
||||
mounted() {
|
||||
const { id: hashtag } = this.$route.params
|
||||
this.$router.push({ path: '/', query: { hashtag } })
|
||||
let { id: hashtag } = this.$route.params
|
||||
// 'hashtag' seems automatically 'decodeURI' on macOS Firefox. Don't know if this is always the case.
|
||||
this.$router.push({ path: '/', query: { hashtag: encodeURI(hashtag) } })
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user