Add escapeBreakLine utility and tests for special character handling #165
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request improves the handling of slot values in the
@layerfig/configpackage, especially for multiline and special-character-containing strings. The main change is the introduction of a utility to safely escape line breaks and special characters before slot value insertion, preventing misparsing and rendering issues. Additionally, tests have been added to ensure correct escaping, and the slot replacement logic in sources has been updated accordingly.Escaping and slot value handling:
escapeBreakLineto escape backslashes, double quotes, newlines, carriage returns, and tabs in slot values before insertion, preventing parsing and rendering errors. (packages/config/src/utils/escape-break-line.ts, packages/config/src/utils/escape-break-line.tsR1-R12)Sourceto useescapeBreakLinewhen inserting slot values, and refactored parsing to useJSON.parsedirectly for consistency. (packages/config/src/sources/source.ts, [1] [2] [3]Testing improvements:
escapeBreakLine, covering all relevant escape scenarios including multiline PEM keys and combinations of special characters. (packages/config/src/utils/escape-break-line.test.ts, packages/config/src/utils/escape-break-line.test.tsR1-R74)packages/config/src/config-builder.test.ts, packages/config/src/config-builder.test.tsR202-R226)Documentation and changelog:
.changeset/tasty-baboons-run.md, .changeset/tasty-baboons-run.mdR1-R7)