karaxnim / karax

Karax. Single page applications for Nim.
MIT License
1.08k stars 91 forks source link

Unicode enum string representation issue #41

Closed darkmusic closed 6 years ago

darkmusic commented 6 years ago

There seems to be an issue with using the $ macro on enum strings containing unicode values in karax. You can use karun --run to run the following code, and there should be a javascript error thrown, which can be seen in the browser developer tools.

include karax / prelude

type 
    NavType = enum 
        Home = "Home", 
        Review = "[漢字 Review]"

var 
    currentNav = Review

doAssert(currentNav == Review, "Check 1 failed") # OK
doAssert($Review == "[漢字 Review]", "Check 2 failed") # OK
doAssert($currentNav == $Review, "Check 3 failed")  # Fails here

proc createDom(): VNode =
    result = buildHtml(tdiv()):
        text "Current page: " & $currentNav

setRenderer createDom

The assertion failure message is the following, which indicates the unicode characters in the string are in their escaped form, which is why the final assertion fails.

Uncaught Error: Error: unhandled exception: $currentNav == "[\xE6\xBC\xA2\xE5\xAD\x97 Review]" Check 3 failed [AssertionError]

This same test (without the karax content) works fine as a nim c -r test.

Araq commented 6 years ago

I doubt this is a Karax bug, looks more like a Nim bug to me.

darkmusic commented 6 years ago

OK. I'll move this over to the Nim issues if there isn't one already, thanks.