Updates for handling single and double quotes in html and sparql data getters

This commit is contained in:
hjkhjk54 2012-08-06 19:30:47 +00:00
parent 8225bcf91f
commit 059094be4c
6 changed files with 73 additions and 4 deletions

View file

@ -14,7 +14,7 @@ var processFixedHTMLDataGetterContent = {
//JSON parsing on the server side does not handle single quotes, as it appears it thinks the string has
//ended. Different data getter types may handle apostrophes/single quotes differently
//In this case, this is HTML so it simply html Encodes any apostrophes
htmlValue = processFixedHTMLDataGetterContent.replaceSingleQuote(htmlValue);
htmlValue = processFixedHTMLDataGetterContent.encodeQuotes(htmlValue);
var returnObject = {saveToVar:saveToVarValue, htmlValue:htmlValue, dataGetterClass:this.dataGetterClass};
return returnObject;
},
@ -22,6 +22,8 @@ var processFixedHTMLDataGetterContent = {
populatePageContentSection:function(existingContentObject, pageContentSection) {
var saveToVarValue = existingContentObject["saveToVar"];
var htmlValue = existingContentObject["htmlValue"];
//In displaying the html value for the edit field, replace the encoded quotes with regular quotes
htmlValue = processFixedHTMLDataGetterContent.replaceEncodedWithEscapedQuotes(htmlValue);
//Now find and set value
pageContentSection.find("input[name='saveToVar']").val(saveToVarValue);
pageContentSection.find("textarea[name='htmlValue']").val(htmlValue);
@ -55,7 +57,7 @@ var processFixedHTMLDataGetterContent = {
}
return validationError;
},
replaceSingleQuote:function(inputStr) {
encodeQuotes:function(inputStr) {
return inputStr.replace(/'/g, ''').replace(/"/g, '"');
},
//For the variable name, no single quote should be allowed
@ -65,6 +67,9 @@ var processFixedHTMLDataGetterContent = {
},
stringHasDoubleQuote:function(inputStr) {
return(inputStr.indexOf("\"") != -1);
},
replaceEncodedWithEscapedQuotes: function(inputStr) {
return inputStr.replace(/'/g, "\'").replace(/"/g, "\"");
}

View file

@ -11,6 +11,7 @@ var processSparqlDataGetterContent = {
var variableValue = pageContentSection.find("input[name='saveToVar']").val();
var queryValue = pageContentSection.find("textarea[name='query']").val();
queryValue = processSparqlDataGetterContent.encodeQuotes(queryValue);
var queryModel = pageContentSection.find("input[name='queryModel']").val();
//query model should also be an input
@ -22,7 +23,11 @@ var processSparqlDataGetterContent = {
populatePageContentSection:function(existingContentObject, pageContentSection) {
var saveToVarValue = existingContentObject["saveToVar"];
var queryValue = existingContentObject["query"];
//replace any encoded quotes with escaped quotes that will show up as quotes in the textarea
queryValue = processSparqlDataGetterContent.replaceEncodedWithEscapedQuotes(queryValue);
var queryModelValue = existingContentObject["queryModel"];
//Now find and set value
pageContentSection.find("input[name='saveToVar']").val(saveToVarValue);
pageContentSection.find("textarea[name='query']").val(queryValue);
@ -45,11 +50,45 @@ var processSparqlDataGetterContent = {
if(variableValue == "") {
validationError += pageContentSectionLabel + ": You must supply a variable to save query results. <br />"
}
if(processSparqlDataGetterContent.stringHasSingleQuote(variableValue)) {
validationError += pageContentSectionLabel + ": The variable name should not have an apostrophe . <br />";
}
if(processSparqlDataGetterContent.stringHasDoubleQuote(variableValue)) {
validationError += pageContentSectionLabel + ": The variable name should not have a double quote . <br />";
}
//Check that query model does not have single or double quotes within it
//Uncomment this/adapt this when we actually allow display the query model input
/*
var queryModelValue = pageContentSection.find("input[name='queryModel']").val();
if(processSparqlDataGetterContent.stringHasSingleQuote(queryModelValue)) {
validationError += pageContentSectionLabel + ": The query model should not have an apostrophe . <br />";
}
if(processSparqlDataGetterContent.stringHasDoubleQuote(queryModelValue)) {
validationError += pageContentSectionLabel + ": The query model should not have a double quote . <br />";
}*/
var queryValue = pageContentSection.find("textarea[name='query']").val();
if(queryValue == "") {
validationError += pageContentSectionLabel + ": You must supply a Sparql query. <br />";
}
return validationError;
},
encodeQuotes:function(inputStr) {
return inputStr.replace(/'/g, '&#39;').replace(/"/g, '&quot;');
},
//For the variable name, no single quote should be allowed
//This can be extended for other special characters
stringHasSingleQuote:function(inputStr) {
return(inputStr.indexOf("'") != -1);
},
stringHasDoubleQuote:function(inputStr) {
return(inputStr.indexOf("\"") != -1);
},
replaceEncodedWithEscapedQuotes: function(inputStr) {
return inputStr.replace(/&#39;/g, "\'").replace(/&quot;/g, "\"");
}