Skip to content
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

Properly escape special characters when generating config files #24

Merged
merged 1 commit into from
Feb 17, 2017

Conversation

HowardWolosky
Copy link
Member

We were escaping linefeeds when generating config files, but we
were not escaping back slashes, quote characters or tabs.

@msftclas
Copy link

Hi @HowardWolosky, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!


It looks like you're a Microsoft contributor. If you're full-time or an intern, we DON'T require a Contribution License Agreement. If you are a vendor, please DO sign the electronic Contribution License Agreement. It will take 2 minutes and there's no faxing! https://cla.microsoft.com.

TTYL, MSBOT;

@HowardWolosky HowardWolosky force-pushed the fix/iapConfig branch 2 times, most recently from 531e0e3 to cda9522 Compare February 17, 2017 20:44
[AllowEmptyString()]
[string] $Value
)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to have a comment acknowledging the confusion for future readers.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Escapes special characters within a string for use within a JSON value.

.SYNOPSIS
Escapes special characters within a string for use within a JSON value.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.Description

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. That was from a copy/paste error with Get-SHA512Hash, so I've fixed it there too.


.NOTES
Normalizes newlines and carraige returns to always be \r\n.
#>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: carraige

@HowardWolosky HowardWolosky force-pushed the fix/iapConfig branch 2 times, most recently from ea47c64 to c281045 Compare February 17, 2017 22:52
We were escaping linefeeds when generating config files, but we
were not escaping back slashes, quote characters or tabs.

Creates a helper function for doing the escaping, and then normalizes
our usage of that helper function wherever we need it.
@HowardWolosky HowardWolosky merged commit 6f01e56 into microsoft:master Feb 17, 2017
@HowardWolosky HowardWolosky deleted the fix/iapConfig branch February 17, 2017 22:54
HowardWolosky added a commit to HowardWolosky/StoreBroker that referenced this pull request Aug 14, 2020
Many years ago, microsoft#24 attempted to properly escape special characters
in a string by creating its own `Get-EscapedJsonValue` function, but
that only escaped `\`, `\t`, `\r`, `\n`.  That doesn't cover all the
possible characters needing to be encoded though.

At the time, this clearly seemed like a _good_ idea, but looking back
at this code with more experience, it's not clear to me why I didn't
just use `ConvertTo-Json` directly. Doing that now.
HowardWolosky added a commit to HowardWolosky/StoreBroker that referenced this pull request Aug 14, 2020
Many years ago, microsoft#24 attempted to properly escape special characters
in a string by creating its own `Get-EscapedJsonValue` function, but
that only escaped `\`, `\t`, `\r`, `\n`.  That doesn't cover all the
possible characters needing to be encoded though.

At the time, this clearly seemed like a _good_ idea, but looking back
at this code with more experience, it's not clear to me why I didn't
just use `ConvertTo-Json` directly. Doing that now.

One additional update that needed to be done however was to "escape"
in `tag` and `notesForCertification` with '//' with '\\'.  This isn't
_completely_ correct, but not doing so meant that anything after that
would be improperly flagged as a comment by `Remove-Comment` and then
removed.
HowardWolosky added a commit to HowardWolosky/StoreBroker that referenced this pull request Aug 14, 2020
Many years ago, microsoft#24 attempted to properly escape special characters
in a string by creating its own `Get-EscapedJsonValue` function, but
that only escaped `\`, `\t`, `\r`, `\n`.  That doesn't cover all the
possible characters needing to be encoded though.

At the time, this clearly seemed like a _good_ idea, but looking back
at this code with more experience, it's not clear to me why I didn't
just use `ConvertTo-Json` directly. Doing that now.

One additional update that needed to be done however was to "escape"
in `tag` and `notesForCertification` with '//' with '\\'.  This isn't
_completely_ correct, but not doing so meant that anything after that
would be improperly flagged as a comment by `Remove-Comment` and then
removed.
HowardWolosky added a commit to HowardWolosky/StoreBroker that referenced this pull request Aug 14, 2020
> This is a re-implementation of microsoft#198 for the v2 branch.

Many years ago, microsoft#24 attempted to properly escape special characters in
a string by creating its own `Get-EscapedJsonValue` function, but that
only escaped `\`, `\t`, `\r`, `\n`.  That doesn't cover all the possible
characters needing to be encoded though.

A user had a `<` character (which was properly JSON-escaped as `\u003c`),
but that didn't get escaped by this logic, and thus caused an issue when
trying to get decoded by `ConvertFrom-Json` later on.

Back then, `Get-EscapedJsonValue` must have seemed like a _good_ idea,
but looking back at this code with more experience, it's not clear to me
why I didn't just use `ConvertTo-Json` directly. Doing that now.

One additional update that needed to be done however was to replace `//`
with `\\`  in `tag` and `notesForCertification`.  This isn't _completely_
correct, but not doing so meant that anything after that would be
improperly flagged as a comment by `Remove-Comment` and then removed.
This was found because the same user had a URL in their
`notesForCertification` and the closing JSON was getting stripped out
incorrectly as soon as it found the `//` in `https://....`.
HowardWolosky added a commit to HowardWolosky/StoreBroker that referenced this pull request Aug 14, 2020
> This is a re-implementation of microsoft#198 for the v2 branch.

Many years ago, microsoft#24 attempted to properly escape special characters in
a string by creating its own `Get-EscapedJsonValue` function, but that
only escaped `\`, `\t`, `\r`, `\n`.  That doesn't cover all the possible
characters needing to be encoded though.

A user had a `<` character (which was properly JSON-escaped as `\u003c`),
but that didn't get escaped by this logic, and thus caused an issue when
trying to get decoded by `ConvertFrom-Json` later on.

Back then, `Get-EscapedJsonValue` must have seemed like a _good_ idea,
but looking back at this code with more experience, it's not clear to me
why I didn't just use `ConvertTo-Json` directly. Doing that now.

One additional update that needed to be done however was to replace `//`
with `\\`  in `tag` and `notesForCertification`.  This isn't _completely_
correct, but not doing so meant that anything after that would be
improperly flagged as a comment by `Remove-Comment` and then removed.
This was found because the same user had a URL in their
`notesForCertification` and the closing JSON was getting stripped out
incorrectly as soon as it found the `//` in `https://....`.
HowardWolosky added a commit to HowardWolosky/StoreBroker that referenced this pull request Aug 14, 2020
> This is a re-implementation of microsoft#198 for the v2 branch.

Many years ago, microsoft#24 attempted to properly escape special characters in
a string by creating its own `Get-EscapedJsonValue` function, but that
only escaped `\`, `\t`, `\r`, `\n`.  That doesn't cover all the possible
characters needing to be encoded though.

A user had a `<` character (which was properly JSON-escaped as `\u003c`),
but that didn't get escaped by this logic, and thus caused an issue when
trying to get decoded by `ConvertFrom-Json` later on.

Back then, `Get-EscapedJsonValue` must have seemed like a _good_ idea,
but looking back at this code with more experience, it's not clear to me
why I didn't just use `ConvertTo-Json` directly. Doing that now.

One additional update that needed to be done however was to replace `//`
with `\\`  in `tag` and `notesForCertification`.  This isn't _completely_
correct, but not doing so meant that anything after that would be
improperly flagged as a comment by `Remove-Comment` and then removed.
This was found because the same user had a URL in their
`notesForCertification` and the closing JSON was getting stripped out
incorrectly as soon as it found the `//` in `https://....`.
HowardWolosky added a commit to HowardWolosky/StoreBroker that referenced this pull request Aug 14, 2020
> This is a re-implementation of microsoft#198 for the v2 branch.

Many years ago, microsoft#24 attempted to properly escape special characters in
a string by creating its own `Get-EscapedJsonValue` function, but that
only escaped `\`, `\t`, `\r`, `\n`.  That doesn't cover all the possible
characters needing to be encoded though.

A user had a `<` character (which was properly JSON-escaped as `\u003c`),
but that didn't get escaped by this logic, and thus caused an issue when
trying to get decoded by `ConvertFrom-Json` later on.

Back then, `Get-EscapedJsonValue` must have seemed like a _good_ idea,
but looking back at this code with more experience, it's not clear to me
why I didn't just use `ConvertTo-Json` directly. Doing that now.

One additional update that needed to be done however was to replace `//`
with `\\`  in `tag` and `notesForCertification`.  This isn't _completely_
correct, but not doing so meant that anything after that would be
improperly flagged as a comment by `Remove-Comment` and then removed.
This was found because the same user had a URL in their
`notesForCertification` and the closing JSON was getting stripped out
incorrectly as soon as it found the `//` in `https://....`.
HowardWolosky added a commit that referenced this pull request Aug 19, 2020
* Fix character escaping issues during config generation

Many years ago, #24 attempted to properly escape special characters
in a string by creating its own `Get-EscapedJsonValue` function, but
that only escaped `\`, `\t`, `\r`, `\n`.  That doesn't cover all the
possible characters needing to be encoded though.

At the time, this clearly seemed like a _good_ idea, but looking back
at this code with more experience, it's not clear to me why I didn't
just use `ConvertTo-Json` directly. Doing that now.

One additional update that needed to be done however was to "escape"
in `tag` and `notesForCertification` with '//' with '\\'.  This isn't
_completely_ correct, but not doing so meant that anything after that
would be improperly flagged as a comment by `Remove-Comment` and then
removed.
HowardWolosky added a commit that referenced this pull request Aug 19, 2020
> This is a re-implementation of #198 for the v2 branch.

Many years ago, #24 attempted to properly escape special characters in
a string by creating its own `Get-EscapedJsonValue` function, but that
only escaped `\`, `\t`, `\r`, `\n`.  That doesn't cover all the possible
characters needing to be encoded though.

A user had a `<` character (which was properly JSON-escaped as `\u003c`),
but that didn't get escaped by this logic, and thus caused an issue when
trying to get decoded by `ConvertFrom-Json` later on.

Back then, `Get-EscapedJsonValue` must have seemed like a _good_ idea,
but looking back at this code with more experience, it's not clear to me
why I didn't just use `ConvertTo-Json` directly. Doing that now.

One additional update that needed to be done however was to replace `//`
with `\\`  in `tag` and `notesForCertification`.  This isn't _completely_
correct, but not doing so meant that anything after that would be
improperly flagged as a comment by `Remove-Comment` and then removed.
This was found because the same user had a URL in their
`notesForCertification` and the closing JSON was getting stripped out
incorrectly as soon as it found the `//` in `https://....`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants