@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';
@@ -282,8 +282,19 @@ function createParser() {
282
282
  });
283
283
  }
284
284
  var DOMParser = createParser();
285
+ var LEADING_ZEROS_DEC = /&#0+(?=[0-9])/g;
286
+ var LEADING_ZEROS_HEX = /&#x0+(?=[0-9a-f])/gi;
287
+ var OVERLONG_NUMERIC_REF = /&#(?:x[0-9a-f]{256,}|[0-9]{309,});?/gi;
288
+ function decodeEntities(value) {
289
+ const safe = value.replace(LEADING_ZEROS_DEC, "&#").replace(LEADING_ZEROS_HEX, (m) => m.slice(0, 3)).replace(OVERLONG_NUMERIC_REF, "\uFFFD");
290
+ try {
291
+ return decodeHTML(safe);
292
+ } catch {
293
+ return safe;
294
+ }
295
+ }
285
296
  function decodeImageSrc(src) {
286
- const entityDecoded = he2.decode(src);
297
+ const entityDecoded = decodeEntities(src);
287
298
  try {
288
299
  return decodeURIComponent(entityDecoded).trim();
289
300
  } catch {
@@ -738,7 +749,7 @@ var isSafeNavValue = (value) => {
738
749
  const isRelative = /^(\/\/|\/[^/]?|#|\?|[a-z0-9._\-]+(\/|$))/i.test(trimmed);
739
750
  return isSafeScheme || isRelative;
740
751
  };
741
- var decodeEntities = (input) => input.replace(/&#(\d+);?/g, (_, dec) => String.fromCodePoint(Number(dec))).replace(/&#x([0-9a-f]+);?/gi, (_, hex) => String.fromCodePoint(parseInt(hex, 16)));
752
+ var decodeEntities2 = (input) => input.replace(/&#(\d+);?/g, (_, dec) => String.fromCodePoint(Number(dec))).replace(/&#x([0-9a-f]+);?/gi, (_, hex) => String.fromCodePoint(parseInt(hex, 16)));
742
753
  var isProxyPSrcset = (srcset) => {
743
754
  const base = trimTrailingSlash(getProxyBase());
744
755
  const candidates = srcset.split(",").map((c) => c.trim().split(/\s+/)[0]).filter(Boolean);
@@ -752,7 +763,7 @@ function sanitizeHtml(html) {
752
763
  css: false,
753
764
  // block style attrs entirely for safety
754
765
  onTagAttr: (tag, name, value) => {
755
- const decoded = decodeEntities(value.trim());
766
+ const decoded = decodeEntities2(value.trim());
756
767
  const decodedLower = decoded.toLowerCase();
757
768
  if (name.startsWith("on")) return "";
758
769
  if (tag === "img" && name === "src" && !/^https?:\/\//.test(decodedLower)) return "";
@@ -2178,6 +2189,8 @@ function markdown2Html(obj, forApp = true, _webp = false, parentDomain = "ecency
2178
2189
  cacheSet(key, res);
2179
2190
  return res;
2180
2191
  }
2192
+
2193
+ // src/catch-post-image.ts
2181
2194
  var gifLinkRegex = /\.(gif)$/i;
2182
2195
  function isGifLink(link) {
2183
2196
  return gifLinkRegex.test(link);
@@ -2234,7 +2247,7 @@ function findFirstImageUrl(body, includeBareUrls = false) {
2234
2247
  return candidates[0].url;
2235
2248
  }
2236
2249
  function proxifyFound(src, width, height, format) {
2237
- const decoded = he2.decode(src);
2250
+ const decoded = decodeEntities(src);
2238
2251
  if (isGifLink(decoded)) {
2239
2252
  return proxifyImageSrc(decoded, 0, 0, format);
2240
2253
  }
@@ -2252,7 +2265,7 @@ function getImage(entry, width = 0, height = 0, format = "match") {
2252
2265
  }
2253
2266
  }
2254
2267
  if (meta && typeof meta.image === "string" && meta.image.length > 0) {
2255
- const decodedImage = he2.decode(meta.image);
2268
+ const decodedImage = decodeEntities(meta.image);
2256
2269
  if (isGifLink(decodedImage)) {
2257
2270
  return proxifyImageSrc(decodedImage, 0, 0, format);
2258
2271
  }
@@ -2260,7 +2273,7 @@ function getImage(entry, width = 0, height = 0, format = "match") {
2260
2273
  }
2261
2274
  if (meta && meta.image && !!meta.image.length && meta.image[0]) {
2262
2275
  if (typeof meta.image[0] === "string") {
2263
- const decodedImage = he2.decode(meta.image[0]);
2276
+ const decodedImage = decodeEntities(meta.image[0]);
2264
2277
  if (isGifLink(decodedImage)) {
2265
2278
  return proxifyImageSrc(decodedImage, 0, 0, format);
2266
2279
  }
@@ -2415,7 +2428,7 @@ function postBodySummary(entryBody, length = 200, platform = "web") {
2415
2428
  text2 = joint(text2.split(" "), length);
2416
2429
  }
2417
2430
  if (text2) {
2418
- text2 = he2.decode(text2);
2431
+ text2 = decodeEntities(text2);
2419
2432
  }
2420
2433
  return text2;
2421
2434
  }