-
Notifications
You must be signed in to change notification settings - Fork 163
Fix: Automatically use unicode syntax for token names with non-ASCII characters #476
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
base: master
Are you sure you want to change the base?
Conversation
Fix: Use unicode string literal for token names with non-ASCII characters (OpenZeppelin#475) - Token names with accents/symbols (e.g., "MyTokeć") now use Solidity’s `unicode"..."` syntax to prevent compilation errors. - Double quotes in names/symbols are escaped (`\"`) to avoid syntax issues. - Developers can now use any Unicode name without manual code adjustments. Fixes OpenZeppelin#475
packages/core/solidity/src/erc20.ts
Outdated
@@ -109,13 +109,22 @@ export function buildERC20(opts: ERC20Options): ContractBuilder { | |||
|
|||
return c; | |||
} | |||
// Helper function to format string literals with the `unicode` keyword if they contain non-ASCII characters. | |||
// Also escapes double quotes in the string. | |||
function formatLiteral(str: string): string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's try to make the function name clear and specific enough so we might not need the comment
packages/core/solidity/src/erc20.ts
Outdated
@@ -109,13 +109,22 @@ export function buildERC20(opts: ERC20Options): ContractBuilder { | |||
|
|||
return c; | |||
} | |||
// Helper function to format string literals with the `unicode` keyword if they contain non-ASCII characters. | |||
// Also escapes double quotes in the string. | |||
function formatLiteral(str: string): string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could move this in the utils folder
packages/core/solidity/src/erc20.ts
Outdated
|
||
function addBase(c: ContractBuilder, name: string, symbol: string) { | ||
const ERC20 = { | ||
name: 'ERC20', | ||
path: '@openzeppelin/contracts/token/ERC20/ERC20.sol', | ||
}; | ||
c.addParent(ERC20, [name, symbol]); | ||
// Use formatLiteral to wrap name and symbol appropriately | ||
c.addParent(ERC20, [formatLiteral(name), formatLiteral(symbol)]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great, we should apply this to other contract (not only ERC20) as well maybe in the contract builder
Hey @MKVEERENDRA thanks for submitting this fix ⚡ |
From formatLiteral to sanitize
Fix: Use unicode string literal for token names with non-ASCII characters (#475)
unicode"..."
syntax to prevent compilation errors.\"
) to avoid syntax issues.Fixes #475