-1

So lets say I have a web service script that splits each variable like so...

var variables = source.u_variables.toString().split(';');

When the user enters their variables, if they end the variable with their own ";" will this cause any issues? I'm having a problem with one particular request that was sent over. When I look at the data, it seems the user put their own semicolon after their variables. Could this be an issue?

Example of the data:

Reason for Leaving: Sick
Doctors Note: Yes
Parents Notified: Yes

This was the data we received that was throwing us some issues:

Reason for Leaving: Sick; Flu; Cold;
Doctors Note: Yes
Parents Notified: Yes   
AdamK
  • 63
  • 8

1 Answers1

0

As others have said, yes this will cause issues. One way to handle this if it's a text payload like you posted would be to split on the new line character.

var variables = source.u_variables.toString().split('\n');

Then your variables would have a value of;

[
   'Reason for Leaving: Sick; Flu; Cold;',
   'Doctors Note: Yes',
   'Parents Notified: Yes'
]

It would be best as Nabil-Ali suggested and getting the data in a more consistent data structure, but sometimes, that just isn't possible.

Jace
  • 144
  • 1
  • 9