@@ -70,7 +70,7 @@ const ExampleValues = {
7070let t_InitForm = {
7171 "name" : "Initialize Form" ,
7272 "func" : test_Init ,
73- "golden" : `https://localhost:8082/?first_name=Bob&last_name=Smith&email_address=bob%40something.com&phone_number=1234567890&subscribe_latest_news=true&country_select=1`
73+ "golden" : `https://localhost:8082/?first_name=Bob&last_name=Smith&email_address=bob%40something.com&phone_number=1234567890&subscribe_latest_news=true&country_select=1&json_payload=%7B%22e%22%3A%22ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789%21%23%24%25%26%28%29*%2B%2C.%2F%3A%3B%3C%3D%3E%3F%40%5B%5D%5E_%60%7B%7C%7D%7E%22%7D `
7474} ;
7575
7676/**@type {Test } */
@@ -201,6 +201,11 @@ function test_Init() {
201201 url . searchParams . set ( 'phone_number' , 1234567890 ) ;
202202 url . searchParams . set ( 'subscribe_latest_news' , true ) ;
203203 url . searchParams . set ( 'country_select' , "1" ) ;
204+ // Tests JSON objects/escaping as URL values.
205+ url . searchParams . set ( 'json_payload' , JSON . stringify ( {
206+ "e" : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!#$%&()*+,./:;<=>?@[]^_`{|}~"
207+ } ) ) ;
208+
204209 // Push new state that updates query params without reloading the page.
205210 window . history . pushState ( { } , '' , url ) ;
206211 initedFormOptions = URLForm . Init ( FormOptions ) ;
@@ -264,8 +269,8 @@ function test_GetFormElements() {
264269// Tests retrieval of key:value pairs from the URL.
265270function test_GetURLKeyValue ( ) {
266271 let pairs = URLForm . GetURLKeyValue ( initedFormOptions ) ;
267- let golden = ` {"first_name":"Bob","last_name":"Smith","email_address":"bob@something.com","phone_number":"1234567890","subscribe_latest_news":"true","country_select":"1"}`
268- return JSON . stringify ( pairs ) === golden ;
272+ let golden = { "first_name" :"Bob" , "last_name" :"Smith" , "email_address" :"bob@something.com" , "phone_number" :"1234567890" , "subscribe_latest_news" :"true" , "country_select" :"1" , "json_payload" : "{\"e\":\"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!#$%&()*+,./:;<=>?@[]^_`{|}~\"}" }
273+ return JSON . stringify ( pairs ) === JSON . stringify ( golden ) ;
269274}
270275
271276// Tests Serialize().
0 commit comments