From string validation#75
Conversation
Perform changes suggested by linter; no functional changes.
Make ErrInvalidID a constant instead of a variable. This prevent it from being changed by external packages; a behavior that although allowed by the compiler, should probably be considered an invalid operation.
go test -bench 'FromString*'
goos: darwin
goarch: amd64
pkg: github.com/rs/xid
cpu: Intel(R) Core(TM) i7-6567U CPU @ 3.30GHz
BenchmarkFromString-4 83381887 13.95 ns/op
BenchmarkFromString2-4 57998780 19.95 ns/op
PASS
ok github.com/rs/xid 4.594s
go test -bench 'FromString*' 16.73s user 0.52s system 278% cpu 6.191 total |
|
723335c to
7868550
Compare
|
Verifying that |
|
I will clean up this PR if we decide that we want the semantics of |
|
Updated benchmarks. Before changeNew failing test: After changePassing tests: |
|
LGTM. Do you need to do something more before merge? |
Well, I have some questions.
|
|
Const is fine and same error may be fine as well, I let you judge. I'm not sure a separate error is actionable. |
|
👍 I agree; I will remove the second error. |
|
Done & rebased. |
Update FromString and XID.TextUnmarshal so that it looks for discarded bits in the final source character. This ensures that XIDs that have been manually tampered with in a way that's ignored by base32 decode, will not pass as valid.
|
Fixed commit messages. |
|
Ready for merge 👍 |
Resolves #71.
commit 06d3085 (HEAD -> from-string, smyrman/from-string)
Author: Sindre Myren sindre@clarify.io
Date: Thu Mar 10 19:39:00 2022 +0100
commit f288272
Author: Sindre Myren sindre@clarify.io
Date: Fri Mar 4 09:13:06 2022 +0100
commit 2171fc4
Author: Sindre Myren sindre@clarify.io
Date: Fri Mar 4 09:12:03 2022 +0100
commit b64cbc7
Author: Sindre Myren sindre@clarify.io
Date: Fri Mar 4 09:09:13 2022 +0100