Skip to content

[fork-ffi] integers: toStringAs — For non-decimal bases the digit alphabet is uppercase… #87

@Unisay

Description

@Unisay

Package: purescript-lua-integers
File: src/Data/Int.lua
Function: toStringAs
Class: show-escaping Severity: high

For non-decimal bases the digit alphabet is uppercase ("0123456789ABCDEF..."), so toStringAs hexadecimal 255 yields "FF" and toStringAs hexadecimal 2147483647 yields "7FFFFFFF". The upstream JS is i.toString(radix), which produces LOWERCASE digits. The package's own tests require lowercase: toStringAs hexadecimal 255 == "ff" and toStringAs hexadecimal 2147483647 == "7fffffff" (Test/Data/Int.purs lines 106, 109), and the round-trip doc example fromStringAs hexadecimal "ff" == Just 255 assumes lowercase. The uppercase output fails these assertions.

Current (Lua):

local digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"

Expected: Lowercase alphanumeric digits matching JS Number.prototype.toString(radix), e.g. toStringAs hexadecimal 255 == "ff".

Proposed fix:

local digits = "0123456789abcdefghijklmnopqrstuvwxyz"

Found by the FFI audit; reproduced under Lua 5.1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions