From c87dc71ad567c6082757944f40f533afd928c4fd Mon Sep 17 00:00:00 2001 From: Pavan Kumar Reddy Balireddy Date: Wed, 16 Sep 2026 17:40:10 +0530 Subject: [PATCH] RDKB-66901 : Updated parsers in GET, POST, and file metadata --- jsts/jst_prefix.js | 24 ++-- tests/CMakeLists.txt | 2 + tests/parser/jst_parser_backslash.jst.parsed | 134 ++++++++++++++++-- .../parser/jst_parser_comment_tag.jst.parsed | 134 ++++++++++++++++-- .../jst_parser_include_code_after.jst.parsed | 134 ++++++++++++++++-- .../jst_parser_include_code_before.jst.parsed | 134 ++++++++++++++++-- .../jst_parser_include_malformed_1.jst.parsed | 134 ++++++++++++++++-- .../jst_parser_include_nested.jst.parsed | 134 ++++++++++++++++-- ...include_not_if_in_block_comment.jst.parsed | 134 ++++++++++++++++-- ...arser_include_not_if_in_content.jst.parsed | 134 ++++++++++++++++-- ..._include_not_if_in_line_comment.jst.parsed | 134 ++++++++++++++++-- .../parser/jst_parser_include_once.jst.parsed | 134 ++++++++++++++++-- .../jst_parser_include_runtime.jst.parsed | 134 ++++++++++++++++-- .../jst_parser_include_unknown.jst.parsed | 134 ++++++++++++++++-- tests/parser/jst_parser_line_feeds.jst.parsed | 134 ++++++++++++++++-- .../jst_parser_single_quotes.jst.parsed | 134 ++++++++++++++++-- .../jst_parser_skip_whitespace.jst.parsed | 134 ++++++++++++++++-- ...t_parser_template_block_content.jst.parsed | 134 ++++++++++++++++-- ...st_parser_template_block_string.jst.parsed | 134 ++++++++++++++++-- tests/parser/jst_prefix.js | 113 ++++++++++++--- tests/parser_test.cpp | 90 ++++++++++++ 21 files changed, 2224 insertions(+), 283 deletions(-) diff --git a/jsts/jst_prefix.js b/jsts/jst_prefix.js index 8f3a778..9cb4c7e 100644 --- a/jsts/jst_prefix.js +++ b/jsts/jst_prefix.js @@ -93,7 +93,7 @@ function session_start() { if($_jst_session) return; - if($_val_input == 1) + if($_val_input == 1) { $_val_input = 0; return; @@ -186,11 +186,11 @@ if(postData) var postValues = postData.split('&'); for(var i = 0; i < postValues.length; ++i) { - var postValue = postValues[i].split('='); - if(postValue.length == 2) + var eqIdx = postValues[i].indexOf('='); + if(eqIdx != -1) { - var value = postValue[1].replace(/[+]/g," "); - $_POST[postValue[0]] = decodeURIComponent(value); + var value = postValues[i].substring(eqIdx + 1).replace(/[+]/g," "); + $_POST[postValues[i].substring(0, eqIdx)] = decodeURIComponent(value); } else { @@ -212,17 +212,17 @@ if(filesData) var fileId = null; for(var j = 0; j < fileData.length; ++j) { - var fileValue = fileData[j].split('='); - if(fileValue.length == 2) + var eqIdx = fileData[j].indexOf('='); + if(eqIdx != -1) { if(!fileId) { - fileId = decodeURIComponent(fileValue[1]); + fileId = decodeURIComponent(fileData[j].substring(eqIdx + 1)); $_FILES[fileId]={}; } else { - $_FILES[fileId][decodeURIComponent(fileValue[0])]=decodeURIComponent(fileValue[1]); + $_FILES[fileId][decodeURIComponent(fileData[j].substring(0, eqIdx))]=decodeURIComponent(fileData[j].substring(eqIdx + 1)); } } else @@ -241,10 +241,10 @@ $_GET= (function () var ar = qs.split('&'); for(var i=0; i(prefix_file)), + std::istreambuf_iterator()); + prefix += "\n} catch (e) { throw e; }\n"; + ASSERT_EQ(duk_peval_lstring(ctx, prefix.c_str(), prefix.length()), DUK_EXEC_SUCCESS) + << duk_safe_to_string(ctx, -1); + duk_pop(ctx); +} + +static bool evaluateJavaScriptBoolean(duk_context* ctx, const char* source) +{ + if(duk_peval_string(ctx, source) != DUK_EXEC_SUCCESS) + { + duk_pop(ctx); + return false; + } + + const bool result = duk_get_boolean(ctx, -1); + duk_pop(ctx); + return result; +} + int recurseDirectory(const string& path, vector& files, const string& match) { DIR *dir; @@ -219,6 +292,23 @@ TEST(general, parser) { } } +TEST(general, prefix_preserves_equals_signs_in_request_values) +{ + EnvVarGuard query_string_guard("QUERY_STRING"); + query_string_guard.set("mac_ssid==2"); + + duk_context* ctx = duk_create_heap_default(); + ASSERT_NE(ctx, nullptr); + evaluatePrefixWithRequestData(ctx, "token=abc%3D%3D", + "id=file1&name=config%3Dbackup&type=application%2Foctet-stream"); + + EXPECT_TRUE(evaluateJavaScriptBoolean(ctx, + "$_GET.mac_ssid === '=2' && $_POST.token === 'abc==' && " + "$_FILES.file1.name === 'config=backup'")); + + duk_destroy_heap(ctx); +} + TEST(general, session_create_multiple_calls_succeed) { duk_context* ctx = duk_create_heap_default();