Skip to content

Commit

Permalink
fix: Don't render 'null' in HTML templates
Browse files Browse the repository at this point in the history
  • Loading branch information
mwest1066 committed Apr 1, 2022
1 parent 69b1ad9 commit e1b38f7
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/html/src/index.ts
Expand Up @@ -9,10 +9,13 @@ function escapeValue(value: unknown): string {
return value.map((val) => escapeValue(val)).join('');
} else if (typeof value === 'string' || typeof value === 'number') {
return ejs.escapeXML(String(value));
} else if (value == null) {
// undefined or null -- render nothing
return '';
} else if (typeof value === 'object') {
throw new Error('Cannot interpolate object in template');
throw new Error(`Cannot interpolate object in template: ${JSON.stringify(value)}`);
} else {
// This is undefined, null, or a boolean - don't render anything here.
// This is boolean - don't render anything here.
return '';
}
}
Expand Down

0 comments on commit e1b38f7

Please sign in to comment.