FIX: Force string conversions to UTF-8 "bytes" (#11315)

https://meta.discourse.org/t/cant-create-poll-with-some-chinese-options/170836
This commit is contained in:
chenyxuan 2020-11-24 00:51:05 +08:00 committed by GitHub
parent 3394d994e9
commit defbae4007
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View File

@ -403,10 +403,9 @@ function ii(a, b, c, d, x, s, t) {
}
function md51(s) {
// Converts the string to UTF-8 "bytes" when necessary
if (/[\x80-\xFF]/.test(s)) {
// Converts the string to UTF-8 "bytes"
s = unescape(encodeURI(s));
}
var n = s.length,
state = [1732584193, -271733879, -1732584194, 271733878],
i;

View File

@ -71,6 +71,16 @@ describe PostsController do
expect(json["errors"][0]).to eq(I18n.t("poll.default_poll_must_have_different_options"))
end
it "accepts different Chinese options" do
SiteSetting.default_locale = 'zh_CN'
post :create, params: {
title: title, raw: "[poll]\n- Microsoft Edge\n- Microsoft Edge\n[/poll]"
}, format: :json
expect(response).to be_successful
end
it "should have at least 1 options" do
post :create, params: {
title: title, raw: "[poll]\n[/poll]"