@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.
@@ -1,5 +1,5 @@
1
1
  import { DOMParser as DOMParser$1, XMLSerializer } from '@xmldom/xmldom';
2
- import he2 from 'he';
2
+ import { decodeHTML } from 'entities';
3
3
  import xss from 'xss';
4
4
  import querystring from 'querystring';
5
5
  import { LRUCache } from 'lru-cache';
@@ -280,8 +280,19 @@ function createParser() {
280
280
  });
281
281
  }
282
282
  var DOMParser = createParser();
283
+ var LEADING_ZEROS_DEC = /&#0+(?=[0-9])/g;
284
+ var LEADING_ZEROS_HEX = /&#x0+(?=[0-9a-f])/gi;
285
+ var OVERLONG_NUMERIC_REF = /&#(?:x[0-9a-f]{256,}|[0-9]{309,});?/gi;
286
+ function decodeEntities(value) {
287
+ const safe = value.replace(LEADING_ZEROS_DEC, "&#").replace(LEADING_ZEROS_HEX, (m) => m.slice(0, 3)).replace(OVERLONG_NUMERIC_REF, "\uFFFD");
288
+ try {
289
+ return decodeHTML(safe);
290
+ } catch {
291
+ return safe;
292
+ }
293
+ }
283
294
  function decodeImageSrc(src) {
284
- const entityDecoded = he2.decode(src);
295
+ const entityDecoded = decodeEntities(src);
285
296
  try {
286
297
  return decodeURIComponent(entityDecoded).trim();
287
298
  } catch {
@@ -736,7 +747,7 @@ var isSafeNavValue = (value) => {
736
747
  const isRelative = /^(\/\/|\/[^/]?|#|\?|[a-z0-9._\-]+(\/|$))/i.test(trimmed);
737
748
  return isSafeScheme || isRelative;
738
749
  };
739
- var decodeEntities = (input) => input.replace(/&#(\d+);?/g, (_, dec) => String.fromCodePoint(Number(dec))).replace(/&#x([0-9a-f]+);?/gi, (_, hex) => String.fromCodePoint(parseInt(hex, 16)));
750
+ var decodeEntities2 = (input) => input.replace(/&#(\d+);?/g, (_, dec) => String.fromCodePoint(Number(dec))).replace(/&#x([0-9a-f]+);?/gi, (_, hex) => String.fromCodePoint(parseInt(hex, 16)));
740
751
  var isProxyPSrcset = (srcset) => {
741
752
  const base = trimTrailingSlash(getProxyBase());
742
753
  const candidates = srcset.split(",").map((c) => c.trim().split(/\s+/)[0]).filter(Boolean);
@@ -750,7 +761,7 @@ function sanitizeHtml(html) {
750
761
  css: false,
751
762
  // block style attrs entirely for safety
752
763
  onTagAttr: (tag, name, value) => {
753
- const decoded = decodeEntities(value.trim());
764
+ const decoded = decodeEntities2(value.trim());
754
765
  const decodedLower = decoded.toLowerCase();
755
766
  if (name.startsWith("on")) return "";
756
767
  if (tag === "img" && name === "src" && !/^https?:\/\//.test(decodedLower)) return "";
@@ -10223,6 +10234,8 @@ function markdown2Html(obj, forApp = true, _webp = false, parentDomain = "ecency
10223
10234
  cacheSet(key, res);
10224
10235
  return res;
10225
10236
  }
10237
+
10238
+ // src/catch-post-image.ts
10226
10239
  var gifLinkRegex = /\.(gif)$/i;
10227
10240
  function isGifLink(link) {
10228
10241
  return gifLinkRegex.test(link);
@@ -10279,7 +10292,7 @@ function findFirstImageUrl(body, includeBareUrls = false) {
10279
10292
  return candidates[0].url;
10280
10293
  }
10281
10294
  function proxifyFound(src, width, height, format) {
10282
- const decoded = he2.decode(src);
10295
+ const decoded = decodeEntities(src);
10283
10296
  if (isGifLink(decoded)) {
10284
10297
  return proxifyImageSrc(decoded, 0, 0, format);
10285
10298
  }
@@ -10297,7 +10310,7 @@ function getImage(entry, width = 0, height = 0, format = "match") {
10297
10310
  }
10298
10311
  }
10299
10312
  if (meta && typeof meta.image === "string" && meta.image.length > 0) {
10300
- const decodedImage = he2.decode(meta.image);
10313
+ const decodedImage = decodeEntities(meta.image);
10301
10314
  if (isGifLink(decodedImage)) {
10302
10315
  return proxifyImageSrc(decodedImage, 0, 0, format);
10303
10316
  }
@@ -10305,7 +10318,7 @@ function getImage(entry, width = 0, height = 0, format = "match") {
10305
10318
  }
10306
10319
  if (meta && meta.image && !!meta.image.length && meta.image[0]) {
10307
10320
  if (typeof meta.image[0] === "string") {
10308
- const decodedImage = he2.decode(meta.image[0]);
10321
+ const decodedImage = decodeEntities(meta.image[0]);
10309
10322
  if (isGifLink(decodedImage)) {
10310
10323
  return proxifyImageSrc(decodedImage, 0, 0, format);
10311
10324
  }
@@ -10389,6 +10402,8 @@ function catchPostImage(obj, width = 0, height = 0, format = "match") {
10389
10402
  cacheSet(key, res);
10390
10403
  return res;
10391
10404
  }
10405
+
10406
+ // src/post-body-summary.ts
10392
10407
  var summaryRenderer = new Remarkable({
10393
10408
  html: true,
10394
10409
  breaks: true,
@@ -10460,7 +10475,7 @@ function postBodySummary(entryBody, length = 200, platform = "web") {
10460
10475
  text3 = joint(text3.split(" "), length);
10461
10476
  }
10462
10477
  if (text3) {
10463
- text3 = he2.decode(text3);
10478
+ text3 = decodeEntities(text3);
10464
10479
  }
10465
10480
  return text3;
10466
10481
  }