Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed
- Use `@aegisjsproject/escape` for HTML escaping

## [v0.2.30] - 2026-01-05

### Added
Expand Down
18 changes: 3 additions & 15 deletions dom.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
import { attachListeners } from '@aegisjsproject/callback-registry/events.js';
import { escapeHTML as escape, escapeAttrName, ATTR_NAME_UNSAFE_PATTERN, HTML_REPLACEMENTS } from '@aegisjsproject/escape/html.js';
export const HTML_UNSAFE_PATTERN = /[<>"']|&(?![a-zA-Z\d]{2,5};|#\d{1,3};)/g;
/*eslint no-control-regex: "off"*/
export const ATTR_NAME_UNSAFE_PATTERN = /[\u0000-\u001f\u007f-\u009f\s"'\\/=><&]/g;
export const HTML_REPLACEMENTS = Object.freeze({
'&': '&amp;',
'"': '&quot;',
'\'': '&apos;',
'<': '&lt;',
'>': '&gt;',
});

export const escape = str => (str?.toString?.() ?? '')
.replaceAll(HTML_UNSAFE_PATTERN, char => HTML_REPLACEMENTS[char]);

/**
*
Expand All @@ -23,9 +12,6 @@ export const escapeAttrVal = str => {
return escape(str);
};

export const escapeAttrName = str => (str?.toString?.() ?? '')
.replace(ATTR_NAME_UNSAFE_PATTERN, char => '_' + char.charCodeAt(0).toString(16).padStart(4, '0') + '_');

export function createAttribute(name, value = '', namespace) {
const attr = typeof namespace === 'string'
? document.createAttributeNS(namespace, name)
Expand Down Expand Up @@ -124,3 +110,5 @@ export function replace(target, ...items) {
attachListeners(target instanceof ShadowRoot ? target.host : target);
}
}

export { escapeAttrName, escape, ATTR_NAME_UNSAFE_PATTERN, HTML_REPLACEMENTS };
4 changes: 3 additions & 1 deletion http.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { useDefaultCSP, addScriptSrc, addConnectSrc, addTrustedTypePolicy, lockCSP } from '@aegisjsproject/http-utils/csp.js';
import { useDefaultCSP, addScriptSrc, addImageSrc, addConnectSrc, addTrustedTypePolicy, lockCSP } from '@aegisjsproject/http-utils/csp.js';

addScriptSrc('https://unpkg.com/@shgysk8zer0/', 'https://unpkg.com/@aegisjsproject/');
addImageSrc('blob:');
addConnectSrc('https://icanhazdadjoke.com/');
addTrustedTypePolicy('aegis-router#html', 'aegis-sanitizer#html', 'default');
lockCSP();
Expand Down
42 changes: 34 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,14 @@
"@rollup/plugin-node-resolve": "^16.0.3",
"@rollup/plugin-terser": "^0.4.4",
"@shgysk8zer0/eslint-config": "^1.0.4",
"@shgysk8zer0/importmap": "^1.7.4",
"@shgysk8zer0/polyfills": "^0.5.3",
"eslint": "^9.0.0",
"rollup": "^4.9.6"
},
"dependencies": {
"@aegisjsproject/callback-registry": "^1.0.3",
"@aegisjsproject/escape": "^1.0.4",
"@aegisjsproject/parsers": "^0.1.4",
"@aegisjsproject/router": "^1.1.3",
"@aegisjsproject/sanitizer": "^0.2.4",
Expand Down
1 change: 1 addition & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default [{
'@aegisjsproject/component/component.js',
'@aegisjsproject/callback-registry/callbackRegistry.js',
'@aegisjsproject/callback-registry/events.js',
'@aegisjsproject/escape/html.js',
]
}, {
input: 'core.js',
Expand Down
Loading