Escape special characters in default value table cells#104
Closed
greymoth-jp wants to merge 1 commit into
Closed
Conversation
A default value containing a pipe (e.g. `[sep="|"]` or a RegExp default such as `/a|b/`) was written raw into the Default column of the params and properties tables. The stray `|` splits the table row, so GFM drops the trailing Description cell and that row's description is lost. The sibling Type column already guards against this: union types use an escaped ` \| ` delimiter and type names pass through the escape helper in link.hbs. Run the default value through the same escape helper. escape() now returns non-string input unchanged so numeric and boolean defaults are preserved (it previously returned null, blanking them out).
Author
|
Closing this to clean up my open PRs. It's a small change and not really worth taking up your review time. Sorry for the noise. |
Member
|
We've come across this issue before and there was a reason the code remained the way it is - I can't just can't remember why so my first job was to track down the previous issue thread. But if you are closing, no big deal. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
When a parameter or property default value contains a pipe, it is written raw into the
Defaultcolumn of the generated table. The extra|is read as a column separator, so the row gets one cell too many. GitHub-flavoured markdown then drops the overflowing cell, which means theDescriptionis silently lost.This happens for any default value with a
|in it, for example:Generated table (the descriptions never make it into the rendered output):
Why this column and not the others
The
Typecolumn in the same table already protects against this. Union types are joined with an escaped\|delimiter, and each type name is run through theescapehelper inlink.hbs. So{string|number}renders asstring \| numberand stays inside its cell. TheDefaultcell is the only value cell that emits its content without that escaping.Fix
Run the default value through the existing
escapehelper, the same one the type cells use. I also changedescape()to return non-string input unchanged. It returnednullbefore, and since default values can be numbers or booleans, escaping them directly would otherwise blank them out. The helper is only ever called on strings today, so this does not change any existing output.After the change the pipe is escaped, the rows keep four cells, and the descriptions survive. Numeric and boolean defaults are unaffected.
partials/partial-cache.jsis regenerated vianpm run partials.npm testpasses.