@ultimat3/seo 31.32.0 → 31.34.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultimat3/seo",
3
- "version": "31.32.0",
3
+ "version": "31.34.0",
4
4
  "description": "Enforced SEO: typed meta, JSON-LD, sitemap, robots, feeds, responsive images, perf budgets",
5
5
  "keywords": [
6
6
  "ultimate",
@@ -43,7 +43,7 @@
43
43
  "test": "bun test"
44
44
  },
45
45
  "dependencies": {
46
- "@ultimat3/core": "31.32.0",
47
- "@ultimat3/schema": "31.32.0"
46
+ "@ultimat3/core": "31.34.0",
47
+ "@ultimat3/schema": "31.34.0"
48
48
  }
49
49
  }
package/src/links.ts CHANGED
@@ -1,9 +1,10 @@
1
- // `RouteMeta.links`: the `<link>` tags a route adds to `<head>` beyond the two this package
2
- // already derives (canonical, hreflang). A font preload, a preconnect, a feed. Typed so a rel the
3
- // framework owns elsewhere — `canonical` (`meta.canonical`), `stylesheet` (the surface bundle) —
4
- // is not spellable here, and checked so an href is always a URL a browser fetches: the value lands
5
- // in an attribute of the document every visitor loads, and `javascript:` in a `<link href>` is
6
- // script the page never meant to carry.
1
+ // `RouteMeta.links`: the `<link>` tags a route adds to `<head>` beyond the two this package already
2
+ // derives (canonical, hreflang). A font preload, a preconnect, a feed.
3
+ //
4
+ // Typed so a rel the framework owns elsewhere — `canonical` (`meta.canonical`), `stylesheet` (the
5
+ // surface bundle) — is not spellable here, and checked so an href is always a URL a browser
6
+ // fetches: the value lands in an attribute of the document every visitor loads, and `javascript:`
7
+ // in a `<link href>` is script the page never meant to carry.
7
8
 
8
9
  import { linkInvalid, type SeoError } from './errors';
9
10
  import type { HeadTag } from './meta';
package/src/meta.ts CHANGED
@@ -159,11 +159,23 @@ export function localizedAlternates(
159
159
  : [...cluster, { hreflang: 'x-default', href: fallback.path }];
160
160
  }
161
161
 
162
+ /** One separator a title template puts between the slot and the brand. */
163
+ const TEMPLATE_SEPARATOR = /[\s\-–—|·:>/]/;
164
+
162
165
  /**
163
- * Separators a title template puts between the slot and the brand. Stripped so the BRAND is what
164
- * the containment test reads: `'%s — Ultimate'` means the brand is `Ultimate`, not `— Ultimate`.
166
+ * The template's BRAND: the slot removed and the separators around it stripped, so the
167
+ * containment test reads it: `'%s — Ultimate'` means the brand is `Ultimate`, not `— Ultimate`.
168
+ * Two index walks, never `/^[…]+|[…]+$/g`: its trailing half retried a separator run from each
169
+ * character of it — 9.2 s on a template of 100k spaces (CodeQL polynomial-redos).
165
170
  */
166
- const TEMPLATE_SEPARATORS = /^[\s\-–—|·:>/]+|[\s\-–—|·:>/]+$/g;
171
+ export function templateBrand(template: string): string {
172
+ const text = template.replace(TITLE_SLOT, '');
173
+ let start = 0;
174
+ let end = text.length;
175
+ while (start < end && TEMPLATE_SEPARATOR.test(text[start] ?? '')) start += 1;
176
+ while (end > start && TEMPLATE_SEPARATOR.test(text[end - 1] ?? '')) end -= 1;
177
+ return text.slice(start, end);
178
+ }
167
179
 
168
180
  const WORD_CHARACTER = /[\p{L}\p{N}]/u;
169
181
 
@@ -202,7 +214,7 @@ export function applyTitleTemplate(title: string, template?: string): string {
202
214
  // `renderMeta` runs per request, so the refusal belongs in `validate.ts`'s build gate, where it
203
215
  // can name the file.
204
216
  if (!template.includes(TITLE_SLOT)) return title;
205
- const brand = template.replace(TITLE_SLOT, '').replace(TEMPLATE_SEPARATORS, '');
217
+ const brand = templateBrand(template);
206
218
  if (brand !== '' && containsWord(title, brand)) return title;
207
219
  // A FUNCTION as the replacement, never the string: `replace` expands `$$`, `$&` and `$'` in a
208
220
  // replacement literal, and a title is app data — "Save $$ on shoes" rendered one dollar.
@@ -8,13 +8,16 @@ import {
8
8
  type SitemapSectionConfig,
9
9
  sectionPatterns,
10
10
  sitemapSectionIssues,
11
+ trimTrailingSlashes,
11
12
  } from '@ultimat3/core';
12
13
 
13
14
  export type SitemapSection = SitemapSectionConfig;
14
15
 
15
16
  /** A page's path as a pattern reads it: no query, no fragment, no trailing slash. */
16
17
  function segmentsOf(path: string): readonly string[] {
17
- const bare = path.replace(/[?#].*$/, '').replace(/\/+$/, '');
18
+ // Cut at the first `?` or `#` by index, never `/[?#].*$/`: linear on every engine (CodeQL).
19
+ const cut = path.search(/[?#]/);
20
+ const bare = trimTrailingSlashes(cut === -1 ? path : path.slice(0, cut));
18
21
  return bare === '' ? [] : bare.slice(1).split('/');
19
22
  }
20
23
 
package/src/xml.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  // file adds only what XML needs on top of it — the characters XML cannot carry at all — because a
3
3
  // sitemap, a feed and a <head> tag all fail the same way on an unescaped ampersand.
4
4
 
5
- import { escapeHtml } from '@ultimat3/core';
5
+ import { escapeHtml, trimTrailingSlashes } from '@ultimat3/core';
6
6
 
7
7
  /**
8
8
  * The characters XML 1.0 excludes from `Char`: the C0 controls other than tab, LF and CR, and the
@@ -58,7 +58,7 @@ export function attributes(attrs: Readonly<Record<string, string>>): string {
58
58
  */
59
59
  export function absoluteUrl(baseUrl: string, path: string): string {
60
60
  if (/^https?:\/\//.test(path)) return path;
61
- const base = baseUrl.replace(/\/+$/, '');
61
+ const base = trimTrailingSlashes(baseUrl);
62
62
  const rest = path.replace(/^\/+/, '');
63
63
  return rest === '' ? base : `${base}/${rest}`;
64
64
  }