Changeset 3487266
- Timestamp:
- 03/20/2026 02:49:26 PM (2 weeks ago)
- Location:
- surveyjs/trunk
- Files:
-
- 5 edited
-
ajax_handlers/save_result.php (modified) (2 diffs)
-
ajax_handlers/save_survey.php (modified) (2 diffs)
-
readme.txt (modified) (2 diffs)
-
surveyjs.php (modified) (1 diff)
-
views/results.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
surveyjs/trunk/ajax_handlers/save_result.php
r3446910 r3487266 13 13 if($_SERVER['REQUEST_METHOD'] === 'POST') { 14 14 if(!check_ajax_referer( 'surveyjs-save-result' )) exit; 15 $SurveyId = intval(sanitize_key($_POST['SurveyId'])); 16 $Json = sanitize_text_field($_POST['Json']); 15 $SurveyId = absint( wp_unslash( $_POST['SurveyId'] ?? 0 ) ); 16 $raw_json = wp_unslash( $_POST['Json'] ?? '' ); 17 $Json = $this->sanitize_result_json( $raw_json ); 18 if ( null === $Json ) { 19 wp_send_json_error( 20 array( 21 'message' => 'Invalid survey result payload', 22 ), 23 400 24 ); 25 return; 26 } 17 27 $TableName = 'sjs_results'; 18 28 … … 34 44 } 35 45 } 46 47 private function sanitize_result_json( $raw_json ) { 48 if ( ! is_string( $raw_json ) || '' === trim( $raw_json ) ) { 49 return null; 50 } 51 52 $decoded = json_decode( $raw_json, true ); 53 if ( JSON_ERROR_NONE !== json_last_error() || ! is_array( $decoded ) ) { 54 return null; 55 } 56 57 $sanitized = $this->sanitize_json_value( $decoded ); 58 return wp_json_encode( $sanitized ); 59 } 60 61 private function sanitize_json_value( $value ) { 62 if ( is_array( $value ) ) { 63 $sanitized = array(); 64 foreach ( $value as $key => $item ) { 65 $sanitized[ $key ] = $this->sanitize_json_value( $item ); 66 } 67 return $sanitized; 68 } 69 70 if ( is_string( $value ) ) { 71 return sanitize_text_field( wp_kses( $value, array() ) ); 72 } 73 74 return $value; 75 } 36 76 } 37 77 -
surveyjs/trunk/ajax_handlers/save_survey.php
r3446910 r3487266 16 16 $table_name = $wpdb->prefix . 'sjs_my_surveys'; 17 17 18 $id = sanitize_key($_POST['Id']); 19 $json = current_user_can( 'unfiltered_html' ) ? $_POST['Json'] : wp_kses_post( $_POST['Json'] ); 20 $theme = current_user_can( 'unfiltered_html' ) ? $_POST['Theme'] : wp_kses_post( $_POST['Theme'] ); 18 $id = absint( wp_unslash( $_POST['Id'] ?? 0 ) ); 19 $raw_json = wp_unslash( $_POST['Json'] ?? '' ); 20 $raw_theme = wp_unslash( $_POST['Theme'] ?? '' ); 21 $json = current_user_can( 'unfiltered_html' ) ? $raw_json : wp_kses_post( $raw_json ); 22 $theme = current_user_can( 'unfiltered_html' ) ? $raw_theme : wp_kses_post( $raw_theme ); 21 23 22 24 // create 'theme' column if not exists … … 35 37 ), 36 38 array( 37 'id' => intval($id)39 'id' => $id 38 40 ) 39 41 ); -
surveyjs/trunk/readme.txt
r3446910 r3487266 4 4 Requires at least: 6.4 5 5 Tested up to: 6.9 6 Stable tag: 2.5. 36 Stable tag: 2.5.4 7 7 Requires PHP: 8.2 8 8 … … 80 80 81 81 82 = v2.5. 3=82 = v2.5.4 = 83 83 84 84 == Support == -
surveyjs/trunk/surveyjs.php
r3446910 r3487266 4 4 Plugin URI: https://wordpress.org/plugins/surveyjs 5 5 Description: Easy to use, drag & drop Survey Builder with myriad options. 6 Version: 2.5. 36 Version: 2.5.4 7 7 Author: Devsoft Baltic OÜ 8 8 Author URI: http://devsoftbaltic.com/ -
surveyjs/trunk/views/results.php
r3446910 r3487266 9 9 public static function render() { 10 10 global $wpdb; 11 $surveyId = sanitize_key($_GET['id']);11 $surveyId = absint( wp_unslash( $_GET['id'] ?? 0 ) ); 12 12 $table_name = $wpdb->prefix . 'sjs_results'; 13 13 $query = $wpdb->prepare("SELECT id, json FROM " . esc_sql( $table_name ) . " WHERE surveyId=%d", intval($surveyId)); … … 18 18 $row = $wpdb->get_row($query); 19 19 $surveyJson = isset($row->json) ? $row->json : '{}'; 20 $decodedSurveyJson = self::decode_survey_json( $surveyJson ); 20 21 21 $surveyName = sanitize_text_field( $_GET['name']);22 $surveyName = sanitize_text_field( wp_unslash( $_GET['name'] ?? '' ) ); 22 23 23 24 $deleteResultUri = add_query_arg(array('action' => 'SurveyJS_DeleteResult'), admin_url('admin-ajax.php')); … … 47 48 <script> 48 49 var $ = jQuery; 49 var surveyJson = '<?php echo htmlspecialchars_decode($surveyJson); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>';50 var survey = new Survey.Model( JSON.parse(surveyJson));50 var surveyJson = <?php echo wp_json_encode( $decodedSurveyJson ); ?>; 51 var survey = new Survey.Model(surveyJson); 51 52 52 53 var columns = survey.getAllQuestions().map(function(q) { … … 57 58 survey.data = row; 58 59 var displayValue = q.displayValue; 59 return(60 (typeof displayValue === "string"60 var safeValue = ( 61 typeof displayValue === "string" 61 62 ? displayValue 62 : JSON.stringify(displayValue)) || "" 63 ); 63 : JSON.stringify(displayValue) 64 ) || ""; 65 return $.fn.dataTable.render.text().display(safeValue); 64 66 } 65 67 }; … … 108 110 ?> 109 111 110 function decodeHtml(str) {111 var textarea = document.createElement("textarea");112 textarea.innerHTML = str;113 return textarea.innerText;114 }115 116 112 var data = results.map(function(result) { 117 var replacedResult = decodeHtml(result.json.replace(/\\\"/g, "\"").replace(/\\\\/g, "\\").replace(/\\'/g, "'")); 118 var dataItem = JSON.parse(replacedResult || "{}"); 113 var dataItem = {}; 114 try { 115 dataItem = JSON.parse(result.json || "{}"); 116 } catch (e) { 117 dataItem = {}; 118 } 119 119 dataItem.resultId = result.id; 120 120 return dataItem; … … 151 151 152 152 } 153 154 private static function decode_survey_json( $raw_json ) { 155 if ( ! is_string( $raw_json ) || '' === trim( $raw_json ) ) { 156 return array(); 157 } 158 159 $candidates = array( 160 $raw_json, 161 wp_specialchars_decode( $raw_json, ENT_QUOTES ), 162 stripslashes( $raw_json ), 163 wp_specialchars_decode( stripslashes( $raw_json ), ENT_QUOTES ), 164 ); 165 166 foreach ( $candidates as $candidate ) { 167 $decoded = json_decode( $candidate, true ); 168 if ( JSON_ERROR_NONE !== json_last_error() ) { 169 continue; 170 } 171 172 // Some legacy records store survey JSON as a JSON string (double encoded). 173 if ( is_string( $decoded ) ) { 174 $decoded_twice = json_decode( $decoded, true ); 175 if ( JSON_ERROR_NONE === json_last_error() && is_array( $decoded_twice ) ) { 176 return $decoded_twice; 177 } 178 continue; 179 } 180 181 if ( is_array( $decoded ) ) { 182 return $decoded; 183 } 184 } 185 186 return array(); 187 } 153 188 } 154 189
Note: See TracChangeset
for help on using the changeset viewer.