This repository was archived by the owner on Mar 12, 2020. It is now read-only.
ParseLicense: fix incorrectly stripping BOM#29
Open
thaJeztah wants to merge 1 commit into
Open
Conversation
`bytes.Trim()` takes a cutset as argument, which means that any
character occurring in the cutset will be removed from the start
(and end) of the input.
For example (replacing the BOM characters with readable characters):
```go
license := []byte("BOMMOBhelloBOMMOB")
parsed := bytes.Trim(license, "BOM")
fmt.Println(string(parsed))
```
Will produce:
```
hello
```
This patch updates the function to use `bytes.TrimPrefix()` which
takes a `prefix` as argument, and only removes exact occurrences of
the given prefix:
```go
license := []byte("BOMMOBhelloBOMMOB")
parsed = bytes.TrimPrefix(license, []byte("BOM"))
fmt.Println(string(parsed))
```
Will produce:
```
MOBhelloBOMMOB
```
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Member
Author
|
ping @mason-fish @dhiltgen PTAL |
dhiltgen
approved these changes
Jul 31, 2019
Contributor
dhiltgen
left a comment
There was a problem hiding this comment.
Thanks for adding more test coverage on this part.
The new code is better/more-correct, but given the license server will never stuff a BOM on the end, it's somewhat academic. The change seems fine to me.
Member
Author
|
@dhiltgen @mason-fish good to go? |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
bytes.Trim()takes a cutset as argument, which means that any character occurring in the cutset will be removed from the start (and end) of the input.For example (replacing the BOM characters with readable characters):
Will produce:
This patch updates the function to use
bytes.TrimPrefix()which takes aprefixas argument, and only removes exact occurences of the given prefix:Will produce:
Also see https://play.golang.org/p/H_cFZ80miNV for an example