-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add escape sequence for terminal characters #165
Conversation
I think this would introduce breaking change for keys that contain Please let me know if you consider this as an issue. |
@mochja 🙌 — that's a beautiful PR! Thank you so much for your contribution. I think the escaping looks solid: both in a functional test and statically. The only piece that I'm unsure about is making |
@mochja heads up—since I was in the code, I did a bit of cleaning and (a) renamed the |
Thank you! It allows for escaping |
allows filtering properties that contains special characters `,*()/` use `\` (backslash) for escaping such characters: foo\/bar, will filter JSON property that matches foo/bar.
@nemtsov I reverted the change for making |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks really solid. The only blocker I have is the double-escaping of the reverse solidus, which I mentioned below. I opened a PR with your changes in it, and a fix here: #167 — if that looks good to you, I'll merge it. If you want to make some more changes, please feel free to rebase on top of that or implement it your own way, and I'll review. Thank you!
maybePushName() | ||
tokens.push({ tag: ch }) | ||
} else if (ch === WILDCARD_CHAR && !name.length && !escape) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mochja q: the !name.length
is for stars that follow characters (e.g. a*
), what about stars that precede them (e.g. *a
)? Is it intentional that you must escape them now?
(e.g. $ echo '{"*a":1}' | node ./bin/json-mask.js '*a'
doesn't work and creates a compiled mask: { '*': { type: 'object', properties: { a: [Object] }, filter: true } }
and yet $ echo '{"a*":1}' | node ./bin/json-mask.js 'a*'
does work and has a mask: { 'a*': { type: 'object' } }
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch, this part would have to reworked for this to work, maybe we could use something from #167?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mochja this has been published in v2.0.0 (https://github.com/nemtsov/json-mask/releases/tag/v2.0.0) |
allows filtering properties that contains special characters
,*()/
use
\
(backslash) for escaping such characters:foo\/bar
, will filter JSON property that matchesfoo/bar
fixes #164