Merge pull request #151 from aeternity/fix_numeric_escapes

Fix numeric escapes in strings
This commit is contained in:
Hans Svensson 2019-09-13 08:04:06 +02:00 committed by GitHub
commit a730fcc366
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 1 deletions

View File

@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
### Added ### Added
- Handle numeric escapes, i.e. `"\x19Ethereum Signed Message:\n"`, and similar strings.
### Changed ### Changed
### Removed ### Removed

View File

@ -95,9 +95,11 @@ parse_char([$', C, $']) -> C.
unescape(Str) -> unescape(Str, []). unescape(Str) -> unescape(Str, []).
%% TODO: numeric escapes
unescape([$"], Acc) -> unescape([$"], Acc) ->
list_to_binary(lists:reverse(Acc)); list_to_binary(lists:reverse(Acc));
unescape([$\\, $x, D1, D2 | Chars ], Acc) ->
C = list_to_integer([D1, D2], 16),
unescape(Chars, [C | Acc]);
unescape([$\\, Code | Chars], Acc) -> unescape([$\\, Code | Chars], Acc) ->
Ok = fun(C) -> unescape(Chars, [C | Acc]) end, Ok = fun(C) -> unescape(Chars, [C | Acc]) end,
case Code of case Code of

View File

@ -15,3 +15,5 @@ contract BasicAuth =
entrypoint to_sign(h : hash, n : int) = entrypoint to_sign(h : hash, n : int) =
Crypto.blake2b((h, n)) Crypto.blake2b((h, n))
entrypoint weird_string() : string =
"\x19Weird String\x42\nMore\n"