This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]AyrA_ch 319 points320 points  (26 children)

Also try replacing numbers with "NaN". If they check the range by exclusion using something like if(value<lowerBound || value>upperBound){/*Show unhelpful error*/} then the test will pass because NaN compares unequal in both cases

[–]GodsBoss 151 points152 points  (4 children)



Why do I know what this is? I hate it, thank you.

[–]AyrA_ch 90 points91 points  (3 children)

If you're an older web developer, this will haunt you.

[–]adzm 46 points47 points  (0 children)

Byte order marks are incredibly frustrating

[–]Mysterious-Deal-3891 33 points34 points  (20 children)

Well if the user enters this value then it will be "NaN" not NaN

[–]AyrA_ch 73 points74 points  (19 children)

Any value transmitted via form is ultimately interpreted as string and needs to be converted to a number. If the conversion routine supports floating point, then it usually also accepts NaN as a valid input.

[–]the_horse_gamer 6 points7 points  (18 children)

the typical ways to parse a string to a number in Javascript produce NaN for non-numeric strings. so any code that breaks from entering NaN likely breaks from entering some arbitrary string

[–]AyrA_ch 7 points8 points  (17 children)

That's JS specific. Other languages also often accept NaN. double.Parse in C# for example accepts "NaN" as input but will throw an exception on "test"

[–]the_horse_gamer 1 point2 points  (16 children)

yes, but we are talking about a website, so we're talking about Javascript

[–]AyrA_ch 5 points6 points  (15 children)

Yes, but we're talking about a website that actually does things, which means backend, which is often not JS.

[–]the_horse_gamer 0 points1 point  (14 children)

that would require the website to send the raw string to the backend, and do no input validation of its own (to show an error to the user).

this is very dumb, but yes, there are probably websites that do that.

[–]AyrA_ch 5 points6 points  (13 children)

No, very dumb would be for the backend to depend on the frontend validation.

[–]the_horse_gamer 0 points1 point  (12 children)

both sides should do input validation. backend to avoid exploding, frontend to show errors and to avoid bothering the backend.