mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Follow @alina-beck's PR suggestions
- save regex to descriptive variables
This commit is contained in:
parent
31862ad7d8
commit
9bb0884f89
@ -8,7 +8,7 @@ import { exec, build } from 'xregexp/xregexp-all.js'
|
|||||||
// 2. If it starts with a digit '0-9' than a unicode character has to follow.
|
// 2. If it starts with a digit '0-9' than a unicode character has to follow.
|
||||||
const regX = build('^/search/hashtag/((\\pL+[\\pL0-9]*)|([0-9]+\\pL+[\\pL0-9]*))$')
|
const regX = build('^/search/hashtag/((\\pL+[\\pL0-9]*)|([0-9]+\\pL+[\\pL0-9]*))$')
|
||||||
|
|
||||||
export default function(content) {
|
export default function (content) {
|
||||||
if (!content) return []
|
if (!content) return []
|
||||||
const $ = cheerio.load(content)
|
const $ = cheerio.load(content)
|
||||||
// We can not search for class '.hashtag', because the classes are removed at the 'xss' middleware.
|
// We can not search for class '.hashtag', because the classes are removed at the 'xss' middleware.
|
||||||
@ -20,8 +20,8 @@ export default function(content) {
|
|||||||
.get()
|
.get()
|
||||||
const hashtags = []
|
const hashtags = []
|
||||||
urls.forEach(url => {
|
urls.forEach(url => {
|
||||||
let match
|
const match = exec(url, regX)
|
||||||
if ((match = exec(url, regX)) != null) {
|
if (match != null) {
|
||||||
hashtags.push(match[1])
|
hashtags.push(match[1])
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@ -125,7 +125,6 @@
|
|||||||
[ ] wasSeeded: { type: Boolean }
|
[ ] wasSeeded: { type: Boolean }
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
CALL apoc.load.json("file:${IMPORT_CHUNK_PATH_CQL_FILE}") YIELD value as post
|
CALL apoc.load.json("file:${IMPORT_CHUNK_PATH_CQL_FILE}") YIELD value as post
|
||||||
MERGE (p:Post {id: post._id["$oid"]})
|
MERGE (p:Post {id: post._id["$oid"]})
|
||||||
ON CREATE SET
|
ON CREATE SET
|
||||||
@ -148,8 +147,10 @@ MATCH (c:Category {id: categoryId})
|
|||||||
MERGE (p)-[:CATEGORIZED]->(c)
|
MERGE (p)-[:CATEGORIZED]->(c)
|
||||||
WITH p, post.tags AS tags
|
WITH p, post.tags AS tags
|
||||||
UNWIND tags AS tag
|
UNWIND tags AS tag
|
||||||
WITH apoc.text.replace(tag, '[^\\p{L}0-9]', '') as tagNoSpacesAllowed
|
WITH '[^\\p{L}0-9]' as regexMatchAllNonUnicodeOrDigits
|
||||||
CALL apoc.when(tagNoSpacesAllowed =~ '^((\\p{L}+[\\p{L}0-9]*)|([0-9]+\\p{L}+[\\p{L}0-9]*))$', 'RETURN tagNoSpacesAllowed', '', {tagNoSpacesAllowed: tagNoSpacesAllowed})
|
WITH apoc.text.replace(tag, regexMatchAllNonUnicodeOrDigits, '') as tagNoSpacesAllowed
|
||||||
|
WITH '^((\\p{L}+[\\p{L}0-9]*)|([0-9]+\\p{L}+[\\p{L}0-9]*))$' as regexHashtagMustNotIncludeOnlyDigits
|
||||||
|
CALL apoc.when(tagNoSpacesAllowed =~ regexHashtagMustNotIncludeOnlyDigits, 'RETURN tagNoSpacesAllowed', '', {tagNoSpacesAllowed: tagNoSpacesAllowed})
|
||||||
YIELD value as validated
|
YIELD value as validated
|
||||||
WHERE validated.tagNoSpacesAllowed IS NOT NULL
|
WHERE validated.tagNoSpacesAllowed IS NOT NULL
|
||||||
MERGE (t:Tag { id: validated.tagNoSpacesAllowed, disabled: false, deleted: false })
|
MERGE (t:Tag { id: validated.tagNoSpacesAllowed, disabled: false, deleted: false })
|
||||||
|
|||||||
@ -215,8 +215,7 @@ export default {
|
|||||||
},
|
},
|
||||||
sanitizeQuery(query) {
|
sanitizeQuery(query) {
|
||||||
if (this.suggestionType === HASHTAG) {
|
if (this.suggestionType === HASHTAG) {
|
||||||
// remove all unallowed chars
|
const regexMatchAllNonUnicodeOrDigits = build('[^\\pL0-9]')
|
||||||
const regX = build('[^\\pL0-9]')
|
|
||||||
query = replace(query, regX, '', 'all')
|
query = replace(query, regX, '', 'all')
|
||||||
// if the query is only made of digits, make it empty
|
// if the query is only made of digits, make it empty
|
||||||
return query.replace(/[0-9]/gm, '') === '' ? '' : query
|
return query.replace(/[0-9]/gm, '') === '' ? '' : query
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user