Fix: Automatically use unicode syntax for token names with non-ASCII characters#476
Fix: Automatically use unicode syntax for token names with non-ASCII characters#476CoveMB merged 8 commits intoOpenZeppelin:masterfrom
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
| } | ||
| // 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.
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
| } | ||
| // 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.
We could move this in the utils folder
packages/core/solidity/src/erc20.ts
Outdated
| }; | ||
| 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.
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
|
All contributors have signed the CLA ✍️ ✅ |
|
Hey @MKVEERENDRA please consider signing the CLA |
|
@ericglau any suggestions |
|
Hi, @MKVEERENDRA you'll need to sign the CLA |
|
I confirm that I have read and hereby agree to the OpenZeppelin Contributor License Agreement |
|
recheck |
ericglau
left a comment
There was a problem hiding this comment.
LGTM, thanks!
I noticed Open in Remix causes an error if the contract has Unicode, but opened a separate issue here.
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