You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In JavaScript the string length property returns the size in number of characters, however String.length in OCaml returns the size in bytes.
Length check in SnarkyJS:
class TokenSymbol extends Struct(TokenSymbolPure) {
static get empty() {
return { symbol: '', field: Field(0) };
}
static from(symbol: string): TokenSymbol {
if (symbol.length > 6)
throw Error('Token symbol length should be a maximum of 6');
let field = prefixToField(symbol);
return { symbol, field };
}
}
Length check in OCaml:
module Token_symbol = struct
[%%versioned_binable
module Stable = struct
module V1 = struct
module T = struct
type t = string [@@deriving sexp, equal, compare, hash, yojson]
let to_latest = Fn.id
let max_length = 6
let check (x : t) = assert (String.length x <= max_length)
This can end in an inconsistent size check if non-ASCII characters are used, for example: node:
> a = '₿₿₿₿₿₿';
'₿₿₿₿₿₿'
> a.length
6
> (new TextEncoder().encode(a)).length
18
utop:
# String.length "₿₿₿₿₿₿";;
- : int = 18
The text was updated successfully, but these errors were encountered:
In JavaScript the string length property returns the size in number of characters, however
String.length
in OCaml returns the size in bytes.Length check in SnarkyJS:
Length check in OCaml:
This can end in an inconsistent size check if non-ASCII characters are used, for example:
node:
utop:
The text was updated successfully, but these errors were encountered: