Ghost/ghost/core/test/utils/fixtures
Kevin Ansfield b704530d74
🐛 Fixed unexpected conversion of single-quoted attributes in HTML cards (#19727)
closes ENG-627

We were using `cheerio` to parse+modify+serialize our rendered HTML to modify links for member attribution. Cheerio's serializer has a [long-standing issue](https://github.com/cheeriojs/cheerio/issues/720) (that we've [had to deal with before](https://github.com/TryGhost/SDK/issues/124)) where it replaces single-quote attributes with double-quote attributes. That was resulting in broken rendering when content used single-quotes such as in HTML cards that have JSON data inside a `data-` attribute or otherwise used single-quotes to avoid escaping double-quotes in an attribute value.

- swapped the implementation that uses `cheerio` for one that uses `html5parser` to tokenize the html string, from there we can loop over the tokens and replace the href attribute values in the original string without touching any other part of the content. Avoids a full parse+serialize process which is both more costly and can result unexpected content changes due to serializer opinions.
  - fixes the quote change bug
  - uses tokenization directly to avoid cost of building a full AST
- updated Content API Posts snapshot
  - one of our fixtures has a missing closing tag which we're no longer "fixing" with a full parse+serialize step in the link replacer (keeps modified src closer to original and better matches behaviour elsewhere in the app / without member-attribution applied)
  - the link replacer no longer converts `attr=""` to `attr` (these are equivalent in the HTML spec so no change in behaviour other than preserving the original source html)
- added a benchmark test file comparing the two implementations because the link replacer runs on render so it's used in a hot path
  - new implementation has a 3x performance improvement
  - the separate files with the old/new implementations have been cleaned up but I've left the benchmark test file in place for future reference

Benchmark results comparing implementations:

```
❯ node test/benchmark.js

LinkReplacer
├─ cheerio: 5.03K /s ±2.20%
├─ html5parser: 16.5K /s ±0.43%

Completed benchmark in 0.9976526670455933s
┌─────────────┬─────────┬────────────┬─────────┬───────┐
│   (index)   │ percent │ iterations │ current │  max  │
├─────────────┼─────────┼────────────┼─────────┼───────┤
│   cheerio   │   ''    │ '5.03K/s'  │  5037   │ 5037  │
│ html5parser │   ''    │ '16.5K/s'  │  16534  │ 16534 │
└─────────────┴─────────┴────────────┴─────────┴───────┘
```
2024-03-06 09:11:49 +00:00
..
admin-build 🐛 Fixed missing published Admin assets when running in development 2022-08-04 10:55:35 +02:00
config Fixed rate limit test (#16258) 2023-02-13 15:16:56 +08:00
csv 🐛 Fixed invalid email getting saved for members (#16021) 2022-12-16 16:47:52 +05:30
data Converted Ghost repo into a monorepo 2022-07-20 16:41:05 +02:00
email-service Added an email rendering test for all Koenig cards (#19059) 2023-12-12 16:05:04 -08:00
export Converted Ghost repo into a monorepo 2022-07-20 16:41:05 +02:00
filter-param Fixed import of bson-objectid in accordance to the typings 2022-10-12 14:54:35 +07:00
images 🐛 Fixed storing original files for images (#16117) 2023-01-30 16:40:50 +01:00
import 🔒 Fixed arbitrary file read via symlinks in content import 2023-08-15 13:01:11 +02:00
media 🐛 Fixed uploads of m4a files with audio/mp4 content type 2023-03-01 08:32:21 +01:00
settings 🐛 Fixed sitemaps with no content (#15571) 2022-10-12 14:11:19 +01:00
themes Updated theme fixtures for casper and source (#18677) 2023-10-18 14:51:35 -07:00
urls Converted Ghost repo into a monorepo 2022-07-20 16:41:05 +02:00
cache-rules.js Enabled shared caching of 404 error responses 2022-09-26 14:54:50 +08:00
context.js Converted Ghost repo into a monorepo 2022-07-20 16:41:05 +02:00
data-generator.js 🐛 Fixed unexpected conversion of single-quoted attributes in HTML cards (#19727) 2024-03-06 09:11:49 +00:00
default-settings-browser.json Added portal default plan setting (#19238) 2023-12-06 11:39:58 +01:00
default-settings.json Added portal default plan setting (#19238) 2023-12-06 11:39:58 +01:00
fixtures.json Added recommendation_notifications column to users table (#18304) 2023-09-22 15:35:55 +00:00
test.hbs Converted Ghost repo into a monorepo 2022-07-20 16:41:05 +02:00