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

Android app fails in locales with Indian-Arabic numerals #4156

Closed
DentonGentry opened this issue Mar 13, 2022 · 2 comments · Fixed by tailscale/tailscale-android#41
Closed
Labels

Comments

@DentonGentry
Copy link
Contributor

DentonGentry commented Mar 13, 2022

What is the issue?

In the Java code where we assemble the list of interfaces we have:

sb.append(String.format("%s %d %d %b %b %b %b %b |", nif.getName(),
               nif.getIndex(), nif.getMTU(), nif.isUp(), nif.supportsMulticast(),
               nif.isLoopback(), nif.isPointToPoint(), nif.supportsMulticast()));

In a locale using Indian-Arabic numerals: ۰ ۱ ۲ ۳ ۴ ۵ ۶ ۷ ۸ ۹
the Java code will format the string as: lo ١ ٦٥٥٣٦ true false true false false |

In the Go code which parses this string, we have:

_, err := fmt.Sscanf(fields[0], "%s %d %d %t %t %t %t %t",
	&name, &index, &mtu, &up, &broadcast, &loopback, &pointToPoint, &multicast)

which does not handle these numerals: unable to parse "lo ١ ٦٥٥٣٦ true false true false false |": expected integer


As these strings are purely internal to pass information between the Java runtime and Go environment, they will never be visible to the user. I think the best fix is to set a specific locale in the Java code to format the string.

Steps to reproduce

No response

Are there any recent changes that introduced the issue?

No response

OS

Android

OS version

Android 10

Tailscale version

1.22

Bug report

No response

@DentonGentry DentonGentry changed the title Android app fails in locales with eastern Arabic numerals Android app fails in locales with Indian-Arabic numerals Mar 13, 2022
@bradfitz
Copy link
Member

Awesome bug!

@DentonGentry
Copy link
Contributor Author

DentonGentry commented Mar 13, 2022

"Passing structured data from Java to Go is hard. I know, I'll use strings! What can possibly go wrong with strings?"
^ me, last year.

DentonGentry added a commit to tailscale/tailscale-android that referenced this issue Mar 13, 2022
We use strings to pass structured data from the JVM to Go.
In a locale using Indian-Arabic numerals: ۰ ۱ ۲ ۳ ۴ ۵ ۶ ۷ ۸ ۹
the Java code will format decimal strings using Indian-Arabic
glyphs.

Go doesn't get a locale set automatically by the Android
runtime, so it always parses strings in en-US:
`unable to parse "lo ١ ٦٥٥٣٦ true false true false false |": expected integer`

Make the Java code send en-US strings. These are purely internal
to pass between the two runtimes, they are not shown to the user.

Fixes tailscale/tailscale#4156

Signed-off-by: Denton Gentry <dgentry@tailscale.com>
DentonGentry added a commit to tailscale/tailscale-android that referenced this issue Mar 13, 2022
We use strings to pass structured data from the JVM to Go.
In a locale using Indian-Arabic numerals: ۰ ۱ ۲ ۳ ۴ ۵ ۶ ۷ ۸ ۹
the Java code will format decimal strings using Indian-Arabic
glyphs.

Go doesn't get a locale set automatically by the Android
runtime, so it always parses strings in en-US:
`unable to parse "lo ١ ٦٥٥٣٦ true false true false false |": expected integer`

Make the Java code send en-US strings. These are purely internal
to pass between the two runtimes, they are not shown to the user.

Fixes tailscale/tailscale#4156

Signed-off-by: Denton Gentry <dgentry@tailscale.com>
DentonGentry added a commit to tailscale/tailscale-android that referenced this issue Mar 13, 2022
We use strings to pass structured data from the JVM to Go.
In a locale using Indian-Arabic numerals: ۰ ۱ ۲ ۳ ۴ ۵ ۶ ۷ ۸ ۹
the Java code will format decimal strings using Indian-Arabic
glyphs.

Go doesn't get a locale set automatically by the Android
runtime, so it always parses strings in a default en-US
`unable to parse "lo ١ ٦٥٥٣٦ true false true false false |": expected integer`

Make the Java code format using the ROOT locale. These strings
are purely internal to pass between the two runtimes, they are
not shown to the user.

Fixes tailscale/tailscale#4156

Signed-off-by: Denton Gentry <dgentry@tailscale.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants