Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Std.parseInt on a hexadecimal string followed by \n returns null when targeting neko #7028

Closed
vwr0527 opened this issue May 15, 2018 · 1 comment
Labels
feature-coretype Class, Type, String, Map, Float, Int, Enum, Void, Array, List, etc. platform-neko Everything related to Neko

Comments

@vwr0527
Copy link

vwr0527 commented May 15, 2018

The expression Std.parseInt("0xff000000\n") returns null on Neko. Other target platforms tested were fine.

I don't think it's intended behavior. I tried to reduce this to the most basic example and got this:

class Main
{
	public static function main() 
	{
		trace(Std.parseInt("1234"));
		trace(Std.parseInt("1234\n"));
		trace(Std.parseInt("0xff000000"));
		trace(Std.parseInt("0xff000000\n"));
	}
}

The resulting output was:

Main.hx:5: 1234
Main.hx:6: 1234
Main.hx:7: -16777216
Main.hx:8: null

So, it seems that parseInt should work even if there's a "\n" at the end of the number. But it produces null when fed a hexadecimal string followed by "\n".

Just for additional information:

Compiling to javascript:

Test.js:3340 Main.hx:5: 1234
Test.js:3340 Main.hx:6: 1234
Test.js:3340 Main.hx:7: 4278190080
Test.js:3340 Main.hx:8: 4278190080

Compiling to Flash:

Main.hx:5: 1234
Main.hx:6: 1234
Main.hx:7: 4278190080
Main.hx:8: 4278190080
@markknol markknol added platform-neko Everything related to Neko feature-coretype Class, Type, String, Map, Float, Int, Enum, Void, Array, List, etc. labels Nov 29, 2018
@Simn
Copy link
Member

Simn commented Dec 12, 2018

We are not going to look into fixing neko-specific problems. However, we still review pull requests.

@Simn Simn closed this as completed Dec 12, 2018
tobil4sk added a commit to tobil4sk/neko that referenced this issue Apr 2, 2022
tobil4sk added a commit to tobil4sk/haxec that referenced this issue Apr 2, 2022
tobil4sk added a commit to tobil4sk/haxec that referenced this issue Apr 2, 2022
Simn pushed a commit to HaxeFoundation/neko that referenced this issue Apr 11, 2022
* Fix builtin_int to handle space, +, and - with hex

All whitespace, along with + and - signs are allowed with hexadecimal
notation, to match other haxe targets.

See HaxeFoundation/haxe#10544
and HaxeFoundation/haxe#10545

* Allow trailing text after hex in builtin_int()

HaxeFoundation/haxe#7028
Simn pushed a commit that referenced this issue Jun 8, 2022
* [tests] Add more parseInt and parseFloat tests

- Label tests
- Including some tests from #4132
- Test trailing text after hexadecimal
- Add test to ensure parseInt does not handle scientific notation
- Enable whitespace test for neko, hl, and c++
- Add test for all whitespace
- Unspecify parseInt case where `0x` is not followed by digits
- Test invalid sign usage

* [php] Disable a parseInt test

* [cs,java,jvm,python] Optimise parseInt

- Each part of the Int string is handled separately so we don't have
a single loop with every single check
- Now it also properly handles trailing text after a hexadecimal value

* [js,flash] Cleanup Std.parseInt

js:
- Allow + sign when using hexadecimal notation
- Since ES5, we don't have to worry about Javascript's parseInt allowing
octal so we can avoid the extra checks when targetting ES5+
- Fix #9198

flash:
- Copy js' implementation of Std.parseInt to flash (no need to worry
about octal as it was only supported before flash 9)

* [php] Fix and optimise Std.parseInt

- Allow + in hexadecimal notation
- Ignore all whitespace before checking for hexadecimal prefix
- Use native php functions instead of the slower charAt()
  - Add str_starts_with extern, and polyfill it for php 7

* [lua] Fix parseInt issues

- Handle all whitespace properly
- Do not crash when hexadecimal number is preceded by two signs
- Do not crash when hexadecimal prefix is followed by non hexadecimal
character

* [eval] Fix handling of plus signs in Std.parseInt

- Do not allow multiple signs
- Do not allow + followed by whitespace

* [eval] Allow all whitespace in `Std.parseFloat`

* [tests] Disable a parseFloat test for eval

* [docs] Update parseInt and parseFloat docs

* [tests] Add test for #7028
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-coretype Class, Type, String, Map, Float, Int, Enum, Void, Array, List, etc. platform-neko Everything related to Neko
Projects
None yet
Development

No branches or pull requests

3 participants