From e32d41eb615ded89b55f0b010e6e7ecc4bcac62b Mon Sep 17 00:00:00 2001 From: dzaima Date: Thu, 1 May 2025 22:48:12 +0300 Subject: [PATCH] =?UTF-8?q?improve=20=E2=80=A2ParseFloat=20error=20message?= =?UTF-8?q?=20on=20argument=20with=20codepoints=20=E2=89=A5256?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/builtins/sysfn.c | 7 +++++-- test/cases/system.bqn | 13 +++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/builtins/sysfn.c b/src/builtins/sysfn.c index 1b9099d8..2ff9e2cc 100644 --- a/src/builtins/sysfn.c +++ b/src/builtins/sysfn.c @@ -121,7 +121,10 @@ B parseFloat_c1(B t, B x) { if (isAtm(x)) thrM("•ParseFloat 𝕩: Expected a character list argument"); if (TI(x,elType)!=el_c8) { x = chr_squeeze(x); - if (TI(x,elType)!=el_c8) thrM("•ParseFloat 𝕩: Expected a character list argument"); + if (TI(x,elType)!=el_c8) { + if (elChr(TI(x,elType))) malformed: thrM("•ParseFloat 𝕩: Malformed input"); + thrM("•ParseFloat 𝕩: Expected a character list argument"); + } } usz ia = IA(x); if (RNK(x)!=1) thrM("•ParseFloat 𝕩: Input must have rank 1"); @@ -129,7 +132,7 @@ B parseFloat_c1(B t, B x) { if (ia >= (1<<20)) thrM("•ParseFloat 𝕩: Input too long"); // assumption by ryu_s2d_n u8* data = c8any_ptr(x); f64 res; - if (!ryu_s2d_n(data, ia, &res)) thrM("•ParseFloat 𝕩: Malformed input"); + if (!ryu_s2d_n(data, ia, &res)) goto malformed; decG(x); return m_f64(res); } diff --git a/test/cases/system.bqn b/test/cases/system.bqn index 842dcf3d..99983395 100644 --- a/test/cases/system.bqn +++ b/test/cases/system.bqn @@ -202,9 +202,22 @@ v←1 ⋄ ! •BQN∘•Repr⊸≡ ⟨+,1‿2,+¨,(+V)(V+V),2‿2⥊↕4⟩ 64‿1•bit._cast •ParseFloat¨ "123.456000000000000"‿"123.45600000000002" %% "11101110011111011111100101011000111101001011101101111010000000100001111001111101111110010101100011110100101110110111101000000010"-'0' ! ∧´'e'=•ParseFloat⎊'e'¨ "-"‿"e2"‿"-e2"‿"."‿".e2"‿"123e"‿"123e-"‿"123e+" •ParseFloat "0."∾(n⥊'0')∾"1234e"∾•Repr n←1000000 %% 0.1234 +•ParseFloat 1e6⥊'1' %% ∞ +!"•ParseFloat 𝕩: Input too long" % •ParseFloat 2e6⥊'1' •Repr∘•ParseFloat¨ ⟨"1.23516411460311636e-323", "1.23516411460311637e-323"⟩ %% ⟨"1e¯323","1.5e¯323"⟩ •Repr∘•ParseFloat¨ ⟨"1.235164114603116360e-323", "1.235164114603116361e-323"⟩ %% ⟨"1e¯323","1e¯323"⟩ •Repr∘•ParseFloat¨ ⟨"1.2351641146031163604e-323", "1.2351641146031163605e-323"⟩ %% ⟨"1e¯323","1e¯323"⟩ +!"•ParseFloat 𝕩: Input was empty" % •ParseFloat "" +!"•ParseFloat 𝕩: Input was empty" % •ParseFloat ↕0 +!"•ParseFloat 𝕩: Input must have rank 1" % •ParseFloat <@ +!"•ParseFloat 𝕩: Input must have rank 1" % •ParseFloat 1‿1⥊'1' +!"•ParseFloat 𝕩: Expected a character list argument" % •ParseFloat 48‿49 +!"•ParseFloat 𝕩: Expected a character list argument" % •ParseFloat <48 +!"•ParseFloat 𝕩: Malformed input" % •ParseFloat "1e1e1" +!"•ParseFloat 𝕩: Malformed input" % •ParseFloat ⋈@ +!"•ParseFloat 𝕩: Malformed input" % •ParseFloat ⋈@+254 +!"•ParseFloat 𝕩: Malformed input" % •ParseFloat ⋈@+1111 +!"•ParseFloat 𝕩: Malformed input" % •ParseFloat ⋈@+1114111 # •Fmt •Fmt 123 %% "123"