From 5bff820aaec9183ff8cf8f8929ed28a2a5be3b4c Mon Sep 17 00:00:00 2001 From: Ray Papworth Date: Thu, 26 Dec 2024 20:12:32 +0000 Subject: [PATCH] json encode valid characters so escaped characters don't get changed back to plain characters --- quiz/generic/proof.php | 4 ++-- tools/project_manager/handle_bad_page.php | 4 ++-- tools/proofers/proof_frame_enh.inc | 4 ++-- tools/proofers/spellcheck_text.inc | 4 ++-- tools/proofers/text_frame_std.inc | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/quiz/generic/proof.php b/quiz/generic/proof.php index 16d72624d0..2daf20d6b5 100644 --- a/quiz/generic/proof.php +++ b/quiz/generic/proof.php @@ -24,7 +24,7 @@ } // 'quiz' will result in codepoints for quizzes $quiz = get_project_or_quiz("quiz"); -$valid_character_pattern = build_character_regex_filter($quiz->get_valid_codepoints(), "js"); +$valid_character_pattern = json_encode(build_character_regex_filter($quiz->get_valid_codepoints(), "js")); $header_args = [ "js_files" => [ @@ -32,7 +32,7 @@ "$code_url/tools/proofers/text_data_processor.js", ], "js_data" => " - var validCharacterPattern = '$valid_character_pattern'; + var validCharacterPattern = $valid_character_pattern; ", 'body_attributes' => "onload='top.initializeStuff(1)'", ]; diff --git a/tools/project_manager/handle_bad_page.php b/tools/project_manager/handle_bad_page.php index 108145a806..b226266a66 100644 --- a/tools/project_manager/handle_bad_page.php +++ b/tools/project_manager/handle_bad_page.php @@ -79,7 +79,7 @@ $header = _("Fix Page"); } - $valid_character_pattern = build_character_regex_filter($project->get_valid_codepoints(), "js"); + $valid_character_pattern = json_encode(build_character_regex_filter($project->get_valid_codepoints(), "js")); $header_args = [ "js_files" => [ "$code_url/pinc/3rdparty/xregexp/xregexp-all.js", @@ -88,7 +88,7 @@ "$code_url/tools/project_manager/handle_bad_page.js", ], "js_data" => " - var validCharacterPattern = '$valid_character_pattern'; + var validCharacterPattern = $valid_character_pattern; ", ]; diff --git a/tools/proofers/proof_frame_enh.inc b/tools/proofers/proof_frame_enh.inc index 133610b1ba..89d35400e4 100644 --- a/tools/proofers/proof_frame_enh.inc +++ b/tools/proofers/proof_frame_enh.inc @@ -13,7 +13,7 @@ function echo_proof_frame_enh(PPage $ppage): void global $code_url; $project = new Project($ppage->projectid()); - $valid_character_pattern = build_character_regex_filter($project->get_valid_codepoints(), "js"); + $valid_character_pattern = json_encode(build_character_regex_filter($project->get_valid_codepoints(), "js")); $switch_confirm = json_encode(_('Are you sure you want to save the current page and change layout?')); $revert_confirm = json_encode(_("Are you sure you want to save the current page and revert to the original text for this round?")); @@ -46,7 +46,7 @@ function echo_proof_frame_enh(PPage $ppage): void function ldAll() { top.initializeStuff(1); } - var validCharacterPattern = '$valid_character_pattern'; + var validCharacterPattern = $valid_character_pattern; var standardInterface = false; var switchConfirm = '$switch_confirm'; var revertConfirm = '$revert_confirm'; diff --git a/tools/proofers/spellcheck_text.inc b/tools/proofers/spellcheck_text.inc index 69b36e6fcf..ed032b6210 100644 --- a/tools/proofers/spellcheck_text.inc +++ b/tools/proofers/spellcheck_text.inc @@ -611,7 +611,7 @@ function get_wordcheck_page_header_args(User $user, PPage $ppage): array global $code_url, $word_check_messages; $project = new Project($ppage->projectid()); - $valid_character_pattern = build_character_regex_filter($project->get_valid_codepoints(), "js"); + $valid_character_pattern = json_encode(build_character_regex_filter($project->get_valid_codepoints(), "js")); $storage_key = "proof-enh" . (($user->profile->i_layout == 1) ? "-v" : "-h"); @@ -632,7 +632,7 @@ function get_wordcheck_page_header_args(User $user, PPage $ppage): array "js_data" => get_page_js($user->profile->i_type == 1 ? 2 : 3) . get_control_bar_texts() . " var imageData = $image_data; - var validCharacterPattern = '$valid_character_pattern'; + var validCharacterPattern = $valid_character_pattern; var wordCheckMessages = " . json_encode($word_check_messages) . "; ", diff --git a/tools/proofers/text_frame_std.inc b/tools/proofers/text_frame_std.inc index 2d0886851d..942a5ee021 100644 --- a/tools/proofers/text_frame_std.inc +++ b/tools/proofers/text_frame_std.inc @@ -9,7 +9,7 @@ function echo_text_frame_std(PPage $ppage): void global $code_url; $project = new Project($ppage->projectid()); - $valid_character_pattern = build_character_regex_filter($project->get_valid_codepoints(), "js"); + $valid_character_pattern = json_encode(build_character_regex_filter($project->get_valid_codepoints(), "js")); $switch_confirm = json_encode(_('Are you sure you want to save the current page and change layout?')); $revert_confirm = json_encode(_("Are you sure you want to save the current page and revert to the original text for this round?")); @@ -29,7 +29,7 @@ function echo_text_frame_std(PPage $ppage): void function ldAll() { top.initializeStuff(0); } - var validCharacterPattern = '$valid_character_pattern'; + var validCharacterPattern = $valid_character_pattern; var standardInterface = true; var switchConfirm = '$switch_confirm'; var revertConfirm = '$revert_confirm';