Skip to content

Commit

Permalink
fix(utils): sanitize empty string + trim (#686)
Browse files Browse the repository at this point in the history
  • Loading branch information
seaerchin authored Apr 6, 2023
1 parent f495793 commit 40da111
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/utils/yaml-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ export const sanitizedYamlParse = (
unparsedContent: string
): Record<string, unknown> =>
yaml.parse(unparsedContent, (key, value) =>
typeof value === "string" ? sanitizer.sanitize(value) : value
typeof value === "string" && !!value
? // NOTE: We call `trim` here because post-sanitization,
// there could be an extra space.
// For example: `logo: path <script />`,
// which will be sanitized with a trailing space.
sanitizer.sanitize(value).trim()
: value
)

export const sanitizedYamlStringify = (prestringifiedContent: object): string =>
yaml.stringify(prestringifiedContent, (key, value) =>
typeof value === "string" ? sanitizer.sanitize(value) : value
typeof value === "string" && !!value ? sanitizer.sanitize(value) : value
)

0 comments on commit 40da111

Please sign in to comment.