Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String values "YES" and "NO" converted to Boolean #4

Open
alexhass opened this issue Jul 28, 2014 · 3 comments · May be fixed by #7
Open

String values "YES" and "NO" converted to Boolean #4

alexhass opened this issue Jul 28, 2014 · 3 comments · May be fixed by #7

Comments

@alexhass
Copy link

We found a bug. If a string has a value "NO" what is ISO code of Norwegian it get's converted to "false". This is not correct and should be kept as is as it is a string.

  // Set up our serializer, setting up the key-casing and the value
  // conversion rules.
  serializer = new lib.JsonSerializer()
    .asString( "isoCode" )
  ;

  // Imagine that these keys are all upper-case because they came
  // out of a database (or some other source in which the keys may
  // have been entered without proper casing).
  country = {
    ISOCODE = "NO",
  };

The string must not change as it is a string and not boolean. Any idea how this can be solved in CF10?

@alexhass
Copy link
Author

Looked into the lib and found a solution.

Changed line if ( isNumeric( input )) { to if ( isNumeric( input ) || isBoolean( Input ) ) {.

      if ( ( hint == "string" ) || ( hint == "any" ) ) {

        // If the string appears to be numeric or boolean, then we have to prefix it to make sure
        // ColdFusion doesn't accidentally convert it to a number or boolean value.
        if ( isNumeric( input ) || isBoolean( Input ) ) {

          writeOutput( """" & input & """" );

        } else {

          writeOutput( serializeJson( input ) );

        }

I verified that both YES and NO works.

@alexhass alexhass changed the title String value "NO" converted to Boolean String values "YES" and "NO" converted to Boolean Jul 28, 2014
@getdeformed
Copy link

I found this same bug recently, and came up with the same solution.

@dheighton
Copy link

We also ran into the same issue, and ended up resolving it the same way. Would be nice if it was rolled into the main library. Will submit a pull request if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants