Problem: the hexagonal refactor churns the backend tree for nine more phases; the UI delivery stack (web/ SPA, cmd/desktop Wails wrapper, compose/web image) must move to its own repo first so doc/layout rewrites land once on a backend-only tree. Change: - New repo git.hubris.network/dtoro/oikos-web (v0.33.0): web/, desktop/ (updateURL repointed to oikos-web releases), compose/, own CI (web + desktop jobs), own deploy script (CI-green gate, TOCTOU guard, version-tagged images, prune-to-3), own webhook receiver on :9798 + launchd unit, own compose project publishing the same 8091:80. - Cutover executed on mac-mini in order: oikos stack's web service stopped+removed, oikos-web project brought up on 8091; outer Caddy untouched (targets the published port) — serving + Authentik flow + /wails 404 quirk verified post-cutover. - Stripped from oikos: web/, cmd/desktop/, compose/web/, desktop CI workflow, ci.yml web job, Makefile ui/desktop/desktop-package/install targets, the compose web service, oikos-web from deploy.sh's fallback prune list; wails + go-keyring dropped from go.mod, vendor synced. - README / CONTRIBUTING / AGENTS.md / .agents dev+operations docs now point at the new repo; mbse + mascot design docs carry a path note. Risk: production SPA serving depends on the new pipeline now; rollback is versioned-image re-up of the old web service from a pre-split checkout (port 8091). Desktop builds installed before the split still check dtoro/oikos releases — one manual reinstall, noted in the oikos-web release notes. Verification: go vet, make test (race), make generate-check, golangci (no new findings; baseline down 400→365); post-cutover curls — localhost:8091 200, /wails/runtime.js 404, outer Caddy 302 Authentik.
117 lines
4.0 KiB
JavaScript
117 lines
4.0 KiB
JavaScript
export const xmlReplacer = /["$&'<>\u0080-\uFFFF]/g;
|
|
const xmlCodeMap = new Map([
|
|
[34, """],
|
|
[38, "&"],
|
|
[39, "'"],
|
|
[60, "<"],
|
|
[62, ">"],
|
|
]);
|
|
// For compatibility with node < 4, we wrap `codePointAt`
|
|
export const getCodePoint =
|
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
String.prototype.codePointAt == null
|
|
? (c, index) => (c.charCodeAt(index) & 64512) === 55296
|
|
? (c.charCodeAt(index) - 55296) * 1024 +
|
|
c.charCodeAt(index + 1) -
|
|
56320 +
|
|
65536
|
|
: c.charCodeAt(index)
|
|
: // http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
|
|
(input, index) => input.codePointAt(index);
|
|
/**
|
|
* Encodes all non-ASCII characters, as well as characters not valid in XML
|
|
* documents using XML entities.
|
|
*
|
|
* If a character has no equivalent entity, a
|
|
* numeric hexadecimal reference (eg. `ü`) will be used.
|
|
*/
|
|
export function encodeXML(input) {
|
|
let returnValue = "";
|
|
let lastIndex = 0;
|
|
let match;
|
|
while ((match = xmlReplacer.exec(input)) !== null) {
|
|
const { index } = match;
|
|
const char = input.charCodeAt(index);
|
|
const next = xmlCodeMap.get(char);
|
|
if (next === undefined) {
|
|
returnValue += `${input.substring(lastIndex, index)}&#x${getCodePoint(input, index).toString(16)};`;
|
|
// Increase by 1 if we have a surrogate pair
|
|
lastIndex = xmlReplacer.lastIndex += Number((char & 64512) === 55296);
|
|
}
|
|
else {
|
|
returnValue += input.substring(lastIndex, index) + next;
|
|
lastIndex = index + 1;
|
|
}
|
|
}
|
|
return returnValue + input.substr(lastIndex);
|
|
}
|
|
/**
|
|
* Encodes all non-ASCII characters, as well as characters not valid in XML
|
|
* documents using numeric hexadecimal reference (eg. `ü`).
|
|
*
|
|
* Have a look at `escapeUTF8` if you want a more concise output at the expense
|
|
* of reduced transportability.
|
|
*
|
|
* @param data String to escape.
|
|
*/
|
|
export const escape = encodeXML;
|
|
/**
|
|
* Creates a function that escapes all characters matched by the given regular
|
|
* expression using the given map of characters to escape to their entities.
|
|
*
|
|
* @param regex Regular expression to match characters to escape.
|
|
* @param map Map of characters to escape to their entities.
|
|
*
|
|
* @returns Function that escapes all characters matched by the given regular
|
|
* expression using the given map of characters to escape to their entities.
|
|
*/
|
|
function getEscaper(regex, map) {
|
|
return function escape(data) {
|
|
let match;
|
|
let lastIndex = 0;
|
|
let result = "";
|
|
while ((match = regex.exec(data))) {
|
|
if (lastIndex !== match.index) {
|
|
result += data.substring(lastIndex, match.index);
|
|
}
|
|
// We know that this character will be in the map.
|
|
result += map.get(match[0].charCodeAt(0));
|
|
// Every match will be of length 1
|
|
lastIndex = match.index + 1;
|
|
}
|
|
return result + data.substring(lastIndex);
|
|
};
|
|
}
|
|
/**
|
|
* Encodes all characters not valid in XML documents using XML entities.
|
|
*
|
|
* Note that the output will be character-set dependent.
|
|
*
|
|
* @param data String to escape.
|
|
*/
|
|
export const escapeUTF8 = /* #__PURE__ */ getEscaper(/["&'<>]/g, xmlCodeMap);
|
|
/**
|
|
* Encodes all characters that have to be escaped in HTML attributes,
|
|
* following {@link https://html.spec.whatwg.org/multipage/parsing.html#escapingString}.
|
|
*
|
|
* @param data String to escape.
|
|
*/
|
|
export const escapeAttribute =
|
|
/* #__PURE__ */ getEscaper(/["&\u00A0]/g, new Map([
|
|
[34, """],
|
|
[38, "&"],
|
|
[160, " "],
|
|
]));
|
|
/**
|
|
* Encodes all characters that have to be escaped in HTML text,
|
|
* following {@link https://html.spec.whatwg.org/multipage/parsing.html#escapingString}.
|
|
*
|
|
* @param data String to escape.
|
|
*/
|
|
export const escapeText = /* #__PURE__ */ getEscaper(/[&<>\u00A0]/g, new Map([
|
|
[38, "&"],
|
|
[60, "<"],
|
|
[62, ">"],
|
|
[160, " "],
|
|
]));
|
|
//# sourceMappingURL=escape.js.map
|