Can't create poll with some Chinese options

[poll name=poll2 type=regular results=always chartType=bar]
* Microsoft Edge(新)
* Microsoft Edge(旧)
[/poll]

When I was trying to create the poll as above, I met with “Poll must have different options”.

After debugging, I figure out that there’s some wrong with the md5 function:

https://github.com/discourse/discourse/blob/dbec3792b7331a79078faa2b8f0def339ea7e912/plugins/poll/assets/javascripts/lib/discourse-markdown/poll.js.es6#L469-L471

md5("Microsoft Edge(新)") = 695bf1ac483d572e5311e3bc9574616a
md5("Microsoft Edge(旧)") = 695bf1ac483d572e5311e3bc9574616a

This seems weird…

I looked through the code and found that /[\x80-\xFF]/.test(s) in L407 can’t correctly detect these Chinese strings.

I fixed this by forcing a conversion to UTF-8 “bytes” and made a PR to your official repo.


BTW, the following poll can’t be created, neither.

[poll name=poll1 type=regular results=always chartType=bar]
* 华东其他地区
* 华南其他地区
* 华北其他地区
[/poll]
5 Likes

Thank You!

https://github.com/discourse/discourse/pull/11315/files

Change looks safe, but we need to confirm that there are no backwards compatibility concerns here. @zogstrip can you have a quick look at the PR?

3 Likes

This was merged so I’m going to close the issue.

1 Like