Text Constraints for Survey123

1424
8
03-13-2019 09:37 AM
joerodmey
MVP Alum

Wanting to not let users enter any quotes, single or double and then replace that with either brackets specifying what was omitted. Ex: if user enters "My name is Joe" the output should be (dbl quote) My name is Joe (dbl quote)

0 Kudos
8 Replies
JamesTedrick
Esri Esteemed Contributor

Hi Joe,

Is there a particular concern about allowing text with single/double quotes be submitted?  The most likely concerns relate to escaping text to attempt to cause unwanted DBMS behavior.  ArcGIS Online and Enterprise normally address these concerns through the use of Standardized SQL functions in ArcGIS Online—ArcGIS Online Help | ArcGIS and other sanitizing procedures.

You can test for the presence of a quotation mark (or any other character) through the use of a regex() function; to invalidate for single or double quotes you would want the following function in your constraint:

not(regex('"|\x27')) 

Note that this will also catch the use of ' as a possessive marker or contraction marker as well.

If you wanted to replace the single/double quotes, then you would need to use a custom JS function.

0 Kudos
joerodmey
MVP Alum

My workflow involves Integromat which pushes to a feature service using JSON and REST. Because of JSON syntax, all of my dynamic data (which is passed in from a survey webhook) must be enclosed in double quotes. Since one of my data pieces that user enters in the survey is a textbox, there is a chance that double quotes could be entered which could throw off the JSON syntax.

This is a sample JSON response of mine:

[
{"attributes" : 
{"OBJECTID" :268,
"Terracon_Comments" :"This is a sample comment which may include "double quotes""
}
}
]

My goal is to allow the user the enter double quotes and not throw off JSON.
Integromt doesn't seem to recognize JSON escaping (or I'm doing it wrong)
0 Kudos
JamesTedrick
Esri Esteemed Contributor

Hi Joe,

In that situation, I would use either Integromat's encodeURL or replace functions to substitute the quotation marks.

0 Kudos
joerodmey
MVP Alum

Will encoding throw off the JSON syntax or REST?

0 Kudos
JamesTedrick
Esri Esteemed Contributor

On the destination web service, you may need to decode the text, but they may also happen automatically depending on the framework you are using.

0 Kudos
joerodmey
MVP Alum

I'm pushing the data to an ESRI feature service.

0 Kudos
joerodmey
MVP Alum

Will the ESRI service automatically decode this? I'm just trying to pass into a ESRI service using REST

0 Kudos
JamesTedrick
Esri Esteemed Contributor

Yes, it should be able to automatically handle an encoded URL.

0 Kudos