Skip to content

Commit 3cf7ed4

Browse files
committed
feat: shortlink fix
1 parent e0fa9f4 commit 3cf7ed4

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

libraries/nestjs-libraries/src/short-linking/short.link.service.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ export class ShortLinkService {
3737
}
3838

3939
const mergeMessages = messages.join(' ');
40-
const urlRegex = /(https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&//=]*))/gm;
40+
const urlRegex =
41+
/(https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&//=]*))/gm;
4142
const urls = mergeMessages.match(urlRegex);
4243
if (!urls) {
4344
// No URLs found, return the original text
@@ -49,12 +50,20 @@ export class ShortLinkService {
4950
);
5051
}
5152

52-
async convertTextToShortLinks(id: string, messages: string[]) {
53+
async convertTextToShortLinks(id: string, messagesList: string[]) {
5354
if (ShortLinkService.provider.shortLinkDomain === 'empty') {
54-
return messages;
55+
return messagesList;
5556
}
5657

57-
const urlRegex = /(https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&//=]*))/gm;
58+
const messages = messagesList.map((text) => {
59+
return text
60+
.replace(/&/g, '&')
61+
.replace(/?/g, '?')
62+
.replace(/#/g, '#');
63+
});
64+
65+
const urlRegex =
66+
/(https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&//=]*))/gm;
5867
return Promise.all(
5968
messages.map(async (text) => {
6069
const urls = uniq(text.match(urlRegex));

0 commit comments

Comments
 (0)