Can't create poll with some Chinese options

AI-generated summary

A user, chenyxuan, encountered an issue while trying to create a poll with Chinese options, receiving the error message “Poll must have different options.” After debugging, they discovered that the problem lay in the md5 function, which failed to correctly handle Chinese characters. They proposed a fix by forcing a conversion to UTF-8 “bytes” and submitted a pull request to the official Discourse repository. The issue was reviewed by sam, who confirmed the change looked safe but required further verification for backwards compatibility. The pull request was later merged by eviltrout, resolving the issue.

[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:

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