@ecency/render-helper 2.5.27 → 2.5.28
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/dist/browser/index.js +21 -8
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.cjs +23 -9
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.mjs +23 -8
- package/dist/node/index.mjs.map +1 -1
- package/package.json +2 -3
package/dist/node/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var xmldom = require('@xmldom/xmldom');
|
|
4
|
-
var
|
|
4
|
+
var entities$1 = require('entities');
|
|
5
5
|
var xss = require('xss');
|
|
6
6
|
var querystring = require('querystring');
|
|
7
7
|
var lruCache = require('lru-cache');
|
|
@@ -28,7 +28,6 @@ function _interopNamespace(e) {
|
|
|
28
28
|
return Object.freeze(n);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
var he2__default = /*#__PURE__*/_interopDefault(he2);
|
|
32
31
|
var xss__default = /*#__PURE__*/_interopDefault(xss);
|
|
33
32
|
var querystring__default = /*#__PURE__*/_interopDefault(querystring);
|
|
34
33
|
var htmlparser2__namespace = /*#__PURE__*/_interopNamespace(htmlparser2);
|
|
@@ -308,8 +307,19 @@ function createParser() {
|
|
|
308
307
|
});
|
|
309
308
|
}
|
|
310
309
|
var DOMParser = createParser();
|
|
310
|
+
var LEADING_ZEROS_DEC = /�+(?=[0-9])/g;
|
|
311
|
+
var LEADING_ZEROS_HEX = /�+(?=[0-9a-f])/gi;
|
|
312
|
+
var OVERLONG_NUMERIC_REF = /&#(?:x[0-9a-f]{256,}|[0-9]{309,});?/gi;
|
|
313
|
+
function decodeEntities(value) {
|
|
314
|
+
const safe = value.replace(LEADING_ZEROS_DEC, "&#").replace(LEADING_ZEROS_HEX, (m) => m.slice(0, 3)).replace(OVERLONG_NUMERIC_REF, "\uFFFD");
|
|
315
|
+
try {
|
|
316
|
+
return entities$1.decodeHTML(safe);
|
|
317
|
+
} catch {
|
|
318
|
+
return safe;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
311
321
|
function decodeImageSrc(src) {
|
|
312
|
-
const entityDecoded =
|
|
322
|
+
const entityDecoded = decodeEntities(src);
|
|
313
323
|
try {
|
|
314
324
|
return decodeURIComponent(entityDecoded).trim();
|
|
315
325
|
} catch {
|
|
@@ -764,7 +774,7 @@ var isSafeNavValue = (value) => {
|
|
|
764
774
|
const isRelative = /^(\/\/|\/[^/]?|#|\?|[a-z0-9._\-]+(\/|$))/i.test(trimmed);
|
|
765
775
|
return isSafeScheme || isRelative;
|
|
766
776
|
};
|
|
767
|
-
var
|
|
777
|
+
var decodeEntities2 = (input) => input.replace(/&#(\d+);?/g, (_, dec) => String.fromCodePoint(Number(dec))).replace(/&#x([0-9a-f]+);?/gi, (_, hex) => String.fromCodePoint(parseInt(hex, 16)));
|
|
768
778
|
var isProxyPSrcset = (srcset) => {
|
|
769
779
|
const base = trimTrailingSlash(getProxyBase());
|
|
770
780
|
const candidates = srcset.split(",").map((c) => c.trim().split(/\s+/)[0]).filter(Boolean);
|
|
@@ -778,7 +788,7 @@ function sanitizeHtml(html) {
|
|
|
778
788
|
css: false,
|
|
779
789
|
// block style attrs entirely for safety
|
|
780
790
|
onTagAttr: (tag, name, value) => {
|
|
781
|
-
const decoded =
|
|
791
|
+
const decoded = decodeEntities2(value.trim());
|
|
782
792
|
const decodedLower = decoded.toLowerCase();
|
|
783
793
|
if (name.startsWith("on")) return "";
|
|
784
794
|
if (tag === "img" && name === "src" && !/^https?:\/\//.test(decodedLower)) return "";
|
|
@@ -10251,6 +10261,8 @@ function markdown2Html(obj, forApp = true, _webp = false, parentDomain = "ecency
|
|
|
10251
10261
|
cacheSet(key, res);
|
|
10252
10262
|
return res;
|
|
10253
10263
|
}
|
|
10264
|
+
|
|
10265
|
+
// src/catch-post-image.ts
|
|
10254
10266
|
var gifLinkRegex = /\.(gif)$/i;
|
|
10255
10267
|
function isGifLink(link) {
|
|
10256
10268
|
return gifLinkRegex.test(link);
|
|
@@ -10307,7 +10319,7 @@ function findFirstImageUrl(body, includeBareUrls = false) {
|
|
|
10307
10319
|
return candidates[0].url;
|
|
10308
10320
|
}
|
|
10309
10321
|
function proxifyFound(src, width, height, format) {
|
|
10310
|
-
const decoded =
|
|
10322
|
+
const decoded = decodeEntities(src);
|
|
10311
10323
|
if (isGifLink(decoded)) {
|
|
10312
10324
|
return proxifyImageSrc(decoded, 0, 0, format);
|
|
10313
10325
|
}
|
|
@@ -10325,7 +10337,7 @@ function getImage(entry, width = 0, height = 0, format = "match") {
|
|
|
10325
10337
|
}
|
|
10326
10338
|
}
|
|
10327
10339
|
if (meta && typeof meta.image === "string" && meta.image.length > 0) {
|
|
10328
|
-
const decodedImage =
|
|
10340
|
+
const decodedImage = decodeEntities(meta.image);
|
|
10329
10341
|
if (isGifLink(decodedImage)) {
|
|
10330
10342
|
return proxifyImageSrc(decodedImage, 0, 0, format);
|
|
10331
10343
|
}
|
|
@@ -10333,7 +10345,7 @@ function getImage(entry, width = 0, height = 0, format = "match") {
|
|
|
10333
10345
|
}
|
|
10334
10346
|
if (meta && meta.image && !!meta.image.length && meta.image[0]) {
|
|
10335
10347
|
if (typeof meta.image[0] === "string") {
|
|
10336
|
-
const decodedImage =
|
|
10348
|
+
const decodedImage = decodeEntities(meta.image[0]);
|
|
10337
10349
|
if (isGifLink(decodedImage)) {
|
|
10338
10350
|
return proxifyImageSrc(decodedImage, 0, 0, format);
|
|
10339
10351
|
}
|
|
@@ -10417,6 +10429,8 @@ function catchPostImage(obj, width = 0, height = 0, format = "match") {
|
|
|
10417
10429
|
cacheSet(key, res);
|
|
10418
10430
|
return res;
|
|
10419
10431
|
}
|
|
10432
|
+
|
|
10433
|
+
// src/post-body-summary.ts
|
|
10420
10434
|
var summaryRenderer = new Remarkable({
|
|
10421
10435
|
html: true,
|
|
10422
10436
|
breaks: true,
|
|
@@ -10488,7 +10502,7 @@ function postBodySummary(entryBody, length = 200, platform = "web") {
|
|
|
10488
10502
|
text3 = joint(text3.split(" "), length);
|
|
10489
10503
|
}
|
|
10490
10504
|
if (text3) {
|
|
10491
|
-
text3 =
|
|
10505
|
+
text3 = decodeEntities(text3);
|
|
10492
10506
|
}
|
|
10493
10507
|
return text3;
|
|
10494
10508
|
}
|