Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use letter and number classes in tag replacements #368

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion electron-app/src/server/websites/bluesky/bluesky.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@ export class Bluesky extends Website {

formatTags(tags: string[]) {
return this.parseTags(
tags.map(tag => tag.replace(/[^a-z0-9]/gi, ' ')).map(tag => tag.split(' ').join('')),
tags
.map(tag => tag.replace(/[^\p{Letter}\p{Number}]/giu, ' '))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

q: is this a newer js feature? (and by newer I mean anything after 2018 since I haven't been able to keep up with all the new specs)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh, I didn't check, Perl had this since 2000 so I'd assumed that everyone that copied their regular expressions from there had it too. Looking it up, apparently it was introduced into JavaScript in 2015, so I guess they were 15 years late to the party, but still have had it for a while now.

.map(tag => tag.split(' ').join('')),
{ spaceReplacer: '_' },
).map(tag => `#${tag}`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,9 @@ export abstract class Megalodon extends Website {

formatTags(tags: string[]) {
return this.parseTags(
tags.map(tag => tag.replace(/[^a-z0-9]/gi, ' ')).map(tag => tag.split(' ').join('')),
tags
.map(tag => tag.replace(/[^\p{Letter}\p{Number}]/giu, ' '))
.map(tag => tag.split(' ').join('')),
{ spaceReplacer: '_' },
).map(tag => `#${tag}`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export class MissKey extends Website {
formatTags(tags: string[]) {
return this.parseTags(
tags
.map(tag => tag.replace(/[^a-z0-9]/gi, ' '))
.map(tag => tag.replace(/[^\p{Letter}\p{Number}]/giu, ' '))
.map(tag =>
tag
.split(' ')
Expand Down
4 changes: 3 additions & 1 deletion electron-app/src/server/websites/twitter/twitter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ export class Twitter extends Website {

formatTags(tags: string[]) {
return this.parseTags(
tags.map(tag => tag.replace(/[^a-z0-9]/gi, ' ')).map(tag => tag.split(' ').join('')),
tags
.map(tag => tag.replace(/[^\p{Letter}\p{Number}]/giu, ' '))
.map(tag => tag.split(' ').join('')),
{ spaceReplacer: '_' },
).map(tag => `#${tag}`);
}
Expand Down