Skip to content

Commit

Permalink
Added new sanitizeValue export
Browse files Browse the repository at this point in the history
  • Loading branch information
jsimck committed Jun 20, 2024
1 parent ae5fd08 commit dacb705
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/stale-bottles-press.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ima/server": minor
---

Added new `sanitizeValue` function export.
2 changes: 2 additions & 0 deletions packages/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const { createMonitoring } = require('@esmj/monitor');
const { Emitter, Event } = require('./lib/emitter.js');
const environmentFactory = require('./lib/factory/environmentFactory');
const urlParserFactory = require('./lib/factory/urlParserFactory');
const { sanitizeValue } = require('./lib/factory/utils/metaUtils');
const {
renderStyles,
renderScript,
Expand Down Expand Up @@ -101,5 +102,6 @@ module.exports = {
createIMAServer,
environmentFactory,
urlParserFactory,
sanitizeValue,
Event,
};
4 changes: 2 additions & 2 deletions packages/server/lib/factory/utils/metaUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function encodeHTMLEntities(value) {
* @param value Attribute value to sanitize
* @returns string|null Sanitized valid value or null
*/
function _sanitizeValue(value) {
export function sanitizeValue(value) {
return value === undefined || value === null
? null
: encodeHTMLEntities(value);
Expand All @@ -77,7 +77,7 @@ function _getMetaTags(iterator, tagName, keyName) {
};

for (let [attrName, attrValue] of Object.entries(attributes)) {
const sanitizedAttrValue = _sanitizeValue(attrValue);
const sanitizedAttrValue = sanitizeValue(attrValue);

// Skip empty values
if (sanitizedAttrValue === null) {
Expand Down
1 change: 1 addition & 0 deletions packages/server/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ declare module '@ima/server' {
devUtils?: any;
});

export function sanitizeValue(value: unknown): null | string;
export function renderStyles(styles: any[]): string;
export function renderScript(name: string, script: string): string;
export function environmentFactory(args: {
Expand Down

0 comments on commit dacb705

Please sign in to comment.