Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions jsts/jst_prefix.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function session_start()
{
if($_jst_session)
return;
if($_val_input == 1)
if($_val_input == 1)
{
$_val_input = 0;
return;
Expand Down Expand Up @@ -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
{
Expand All @@ -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
Expand All @@ -241,10 +241,10 @@ $_GET= (function ()
var ar = qs.split('&');
for(var i=0; i<ar.length; ++i)
{
var ar2 = ar[i].split('=');
if(ar2.length != 2)
var eqIdx = ar[i].indexOf('=');
if(eqIdx == -1)
throw Error("$_GET: Invalid QUERY_STRING");
out[ar2[0]] = ar2[1];
out[ar[i].substring(0, eqIdx)] = ar[i].substring(eqIdx + 1);
}
}
return out;
Expand Down
2 changes: 1 addition & 1 deletion source/jst_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ static int template_process(char** buf, size_t* buflen, int top)
char filepath[MAX_PATH_LEN];
growing_buffer tbuf1;
growing_buffer tbuf2;
char TEMPL_PATH[MAX_PATH_LEN] = "/usr/video_analytics/";
char TEMPL_PATH[MAX_PATH_LEN] = "/var/video_analytics/";
Comment thread
pavankumar464 marked this conversation as resolved.
buffer_init(&tbuf1);
buffer_init(&tbuf2);

Expand Down
136 changes: 121 additions & 15 deletions tests/parser/jst_parser_backslash.jst.parsed
Original file line number Diff line number Diff line change
@@ -1,19 +1,45 @@
/*
If not stated otherwise in this file or this component's Licenses.txt file the
following copyright and licenses apply:

Copyright 2018 RDK Management

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
try
{
/* HEADERS: accumulate headers into a buffer
to send to stdout in _jst_finish*/
_jst_header_buffer = "Content-type: text/html";
_jst_header_content_type_set = false;
_jst_header_buffer = "";
function header(str)
{
if(str.toLowerCase().indexOf('location:') == 0)
lstr = str.toLowerCase();
if(lstr.indexOf('location:') == 0)
{
_jst_header_buffer = "HTTP/1.0 302 Ok\r\n";
_jst_header_buffer += "Status: 302 Moved\r\n";
_jst_header_buffer += str;
_jst_header_buffer += str + "\r\n";
}
else
{
_jst_header_buffer += "\n" + str;
if(lstr.indexOf('content-type:') == 0)
{
_jst_header_content_type_set = true;
if(lstr.indexOf('application/json') != -1)
_jst_header_buffer += "Content-Type: text/html\r\n";
}
_jst_header_buffer += str + "\r\n";
}
}

Expand All @@ -22,16 +48,17 @@ function header(str)
_jst_echo_buffer = "";
function echo(str)
{
str = (typeof(str)!="undefined") ? str : "";
_jst_echo_buffer += str;
}

/* FINISH: _jst_finish is called at the very end of the script
and it will send the headers and content to stdout */
function _jst_finish()
{
print(_jst_header_buffer);
print("\r\n\r\n\n");
print(_jst_echo_buffer);
if(!_jst_header_content_type_set)
print("Content-type: text/html\r");
print(_jst_header_buffer + "\r\n" + _jst_echo_buffer);
}

/* EXIT: there is no way to simply quit in the middle of a script, so
Expand Down Expand Up @@ -61,12 +88,51 @@ var $_SERVER = new Proxy({}, {
/* SESSION: session data set by web app, saved to disk, and referenced by session id stored in cookie */
var $_SESSION = {};
var $_jst_session = null;
var $_val_input = {};
function session_start()
{
if($_jst_session)
return;
if($_val_input == 1)
{
$_val_input = 0;
return;
}
ccsp_session.start();
header("Set-Cookie: DUKSID=" + ccsp_session.getId() + ";");
var host = getenv('HTTPS');
if (host == false)
var $cookie = "Set-Cookie: DUKSID=" + ccsp_session.getId() + "; httponly";
else
var $cookie = "Set-Cookie: DUKSID=" + ccsp_session.getId() + "; secure" + "; httponly";
header($cookie);
$_jst_session = ccsp_session.getData();
$_SESSION = new Proxy($_jst_session, {
get: function(obj, prop) {
return obj[prop];
},
set: function(obj, prop, val){
obj[prop] = val;
ccsp_session.setData(obj);
return true;
},
deleteProperty(obj, prop) {
if(prop in obj)
{
delete obj[prop];
ccsp_session.setData(obj);
}
return true;
}
});
}
function session_create(){
ccsp_session.create();
var host = getenv('HTTPS');
if (host == false)
var $cookie = "Set-Cookie: DUKSID=" + ccsp_session.getId() + "; httponly";
else
var $cookie = "Set-Cookie: DUKSID=" + ccsp_session.getId() + "; secure" + "; httponly";
header($cookie);
$_jst_session = ccsp_session.getData();
$_SESSION = new Proxy($_jst_session, {
get: function(obj, prop) {
Expand Down Expand Up @@ -120,14 +186,48 @@ 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
{
print("unexpected post data");
$_val_input = 1;
}
}
}

/* FILES: multipart/form-data files via stdin */
$_FILES={};
var filesData = ccsp_post.getFiles();
if(filesData)
{
var fileList = filesData.split(';');
for(var i = 0; i < fileList.length; ++i)
{
var fileData = fileList[i].split('&');
var fileId = null;
for(var j = 0; j < fileData.length; ++j)
{
var eqIdx = fileData[j].indexOf('=');
if(eqIdx != -1)
{
if(!fileId)
{
fileId = decodeURIComponent(fileData[j].substring(eqIdx + 1));
$_FILES[fileId]={};
}
else
{
$_FILES[fileId][decodeURIComponent(fileData[j].substring(0, eqIdx))]=decodeURIComponent(fileData[j].substring(eqIdx + 1));
}
}
else
print("unexpected file data");
}
}
}

Expand All @@ -141,10 +241,10 @@ $_GET= (function ()
var ar = qs.split('&');
for(var i=0; i<ar.length; ++i)
{
var ar2 = ar[i].split('=');
if(ar2.length != 2)
var eqIdx = ar[i].indexOf('=');
if(eqIdx == -1)
throw Error("$_GET: Invalid QUERY_STRING");
out[ar2[0]] = ar2[1];
out[ar[i].substring(0, eqIdx)] = ar[i].substring(eqIdx + 1);
}
}
return out;
Expand All @@ -157,6 +257,12 @@ function include($filepath)

/* begin application code */







echo('a \\ b\n\
');
/* end application code */
Expand Down
Loading
Loading