@evanp/activitypub-bot 0.46.0 → 0.46.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/lib/microsyntax.js +28 -10
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/lib/microsyntax.js
CHANGED
|
@@ -26,12 +26,7 @@ export class Transformer {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
async transform (text) {
|
|
29
|
-
let html = text
|
|
30
|
-
.replace(/&/g, '&')
|
|
31
|
-
.replace(/</g, '<')
|
|
32
|
-
.replace(/>/g, '>')
|
|
33
|
-
.replace(/"/g, '"')
|
|
34
|
-
.replace(/'/g, ''')
|
|
29
|
+
let html = this.#escape(text)
|
|
35
30
|
let tag = [];
|
|
36
31
|
({ html, tag } = this.#replaceUrls(html, tag));
|
|
37
32
|
({ html, tag } = this.#replaceHashtags(html, tag));
|
|
@@ -47,7 +42,8 @@ export class Transformer {
|
|
|
47
42
|
const segment = segments[i]
|
|
48
43
|
if (this.#isLink(segment)) continue
|
|
49
44
|
segments[i] = segment.replace(url, (match) => {
|
|
50
|
-
|
|
45
|
+
const escaped = this.#escape(match)
|
|
46
|
+
return `<a href="${escaped}">${escaped}</a>`
|
|
51
47
|
})
|
|
52
48
|
}
|
|
53
49
|
return { html: segments.join(''), tag }
|
|
@@ -62,7 +58,9 @@ export class Transformer {
|
|
|
62
58
|
segments[i] = segment.replace(hashtag, (match, name) => {
|
|
63
59
|
const href = this.#tagNamespace + name
|
|
64
60
|
tag.push({ type: AS2 + 'Hashtag', name: match, href })
|
|
65
|
-
|
|
61
|
+
const escaped = this.#escape(href)
|
|
62
|
+
const escapedMatch = this.#escape(match)
|
|
63
|
+
return `<a href="${escaped}">${escapedMatch}</a>`
|
|
66
64
|
})
|
|
67
65
|
}
|
|
68
66
|
return { html: segments.join(''), tag }
|
|
@@ -78,8 +76,19 @@ export class Transformer {
|
|
|
78
76
|
segments[i] = await this.#replaceAsync(segments[i], webfinger, async (match) => {
|
|
79
77
|
const href = await self.#homePage(match.slice(1))
|
|
80
78
|
if (!href) return match
|
|
81
|
-
|
|
82
|
-
|
|
79
|
+
let url
|
|
80
|
+
try {
|
|
81
|
+
url = new URL(href)
|
|
82
|
+
} catch (err) {
|
|
83
|
+
return match
|
|
84
|
+
}
|
|
85
|
+
if (url.protocol !== 'https:') {
|
|
86
|
+
return match
|
|
87
|
+
}
|
|
88
|
+
tag.push({ type: 'Mention', name: match, href: url.href })
|
|
89
|
+
const escaped = this.#escape(url.href)
|
|
90
|
+
const escapedMatch = this.#escape(match)
|
|
91
|
+
return `<a href="${escaped}">${escapedMatch}</a>`
|
|
83
92
|
})
|
|
84
93
|
}
|
|
85
94
|
return { html: segments.join(''), tag }
|
|
@@ -157,4 +166,13 @@ export class Transformer {
|
|
|
157
166
|
// Replace the matches with their respective replacements
|
|
158
167
|
return str.replace(regex, () => replacements.shift())
|
|
159
168
|
}
|
|
169
|
+
|
|
170
|
+
#escape (text) {
|
|
171
|
+
return text
|
|
172
|
+
.replace(/&/g, '&')
|
|
173
|
+
.replace(/</g, '<')
|
|
174
|
+
.replace(/>/g, '>')
|
|
175
|
+
.replace(/"/g, '"')
|
|
176
|
+
.replace(/'/g, ''')
|
|
177
|
+
}
|
|
160
178
|
}
|