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

consider validating namespaces onchain #1991

Closed
holic opened this issue Dec 1, 2023 · 2 comments
Closed

consider validating namespaces onchain #1991

holic opened this issue Dec 1, 2023 · 2 comments

Comments

@holic
Copy link
Member

holic commented Dec 1, 2023

to avoid characters like _ (which is meaningful in MUD protocol)

@holic
Copy link
Member Author

holic commented Jan 18, 2024

some untested solidity from ChatGPT

function isAlphanumeric(string memory str) public pure returns (bool) {
    bytes memory b = bytes(str); // Convert string to bytes for low-level handling
    uint256 len = b.length; // Store length of string

    // Inline assembly for direct memory access and reduced gas cost
    assembly {
        // Loop over the string, byte by byte
        for { let i := 0 } lt(i, len) { i := add(i, 1) } {
            let char := byte(0, mload(add(add(b, 0x20), i))) // Load the i-th byte of string

            // Check if the character is not alphanumeric
            if or(
                or(
                    lt(char, 0x30), // Less than '0'
                    and(gt(char, 0x39), lt(char, 0x41)) // Greater than '9' and less than 'A'
                ),
                or(
                    gt(char, 0x5A), // Greater than 'Z'
                    and(lt(char, 0x61), gt(char, 0x7A)) // Less than 'a' or greater than 'z'
                )
            ) {
                // If any character is not alphanumeric, return false
                mstore(0x00, 0)
                return(0x00, 0x20)
            }
        }
    }
    // If all characters are alphanumeric, return true
    return true;
}

@holic
Copy link
Member Author

holic commented Jan 24, 2024

done in #2169 and #2182

@holic holic closed this as completed Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

No branches or pull requests

1 participant