From defbae40070867be5345a3788ae94812aedaee50 Mon Sep 17 00:00:00 2001 From: chenyxuan <30386098+chenyxuan@users.noreply.github.com> Date: Tue, 24 Nov 2020 00:51:05 +0800 Subject: [PATCH] FIX: Force string conversions to UTF-8 "bytes" (#11315) https://meta.discourse.org/t/cant-create-poll-with-some-chinese-options/170836 --- .../javascripts/lib/discourse-markdown/poll.js.es6 | 7 +++---- plugins/poll/spec/controllers/posts_controller_spec.rb | 10 ++++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/plugins/poll/assets/javascripts/lib/discourse-markdown/poll.js.es6 b/plugins/poll/assets/javascripts/lib/discourse-markdown/poll.js.es6 index f71dec46085..9f0d033b79f 100644 --- a/plugins/poll/assets/javascripts/lib/discourse-markdown/poll.js.es6 +++ b/plugins/poll/assets/javascripts/lib/discourse-markdown/poll.js.es6 @@ -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)) { - s = unescape(encodeURI(s)); - } + // Converts the string to UTF-8 "bytes" + s = unescape(encodeURI(s)); + var n = s.length, state = [1732584193, -271733879, -1732584194, 271733878], i; diff --git a/plugins/poll/spec/controllers/posts_controller_spec.rb b/plugins/poll/spec/controllers/posts_controller_spec.rb index 9024c8d6e9e..805641a1882 100644 --- a/plugins/poll/spec/controllers/posts_controller_spec.rb +++ b/plugins/poll/spec/controllers/posts_controller_spec.rb @@ -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]"