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

JSON value '<null>' of type NSNULL canot be converted to NSNumber (iOS) #51

Closed
tuneZola opened this issue May 27, 2016 · 4 comments
Closed

Comments

@tuneZola
Copy link

Example

<Svg height="100" width="100"> 
    <Path 
        fill='red' 
        d="M6.5 1C7.9 1 9 2.1 9 3.5c0 .8-.4 1.6-1.1 2.1-.4.2-.9.4-1.4.4s-1-.2-1.4-.4C4.4 5.1 4 4.3 4 3.5 4 2.1       5.1 1 6.5 1m0-1C4.6 0 3 1.6 3 3.5c0 1.2.6 2.2 1.5 2.9.6.4 1.3.6 2 .6s1.4-.2 2-.6c.9-.7 1.5-1.7 1.5-2.9C10 1.6 8.4 0 6.5 0zm3.6 8.9c.6.8.9 1.7.9 2.6v.5H2v-.5c0-1 .3-1.9.9-2.6 1 .7 2.3 1.1 3.6 1.1s2.6-.4 3.6-1.1m.2-1.4C9.3 8.4 8 9 6.5 9s-2.8-.6-3.8-1.5c-1.1 1-1.7 2.4-1.7 4 0 .5.1 1.5.2 1.5h10.6c.1 0 .2-1 .2-1.5 0-1.6-.7-3-1.7-4z"
    /> 
</Svg> 

Mostly I am having issues at SerializablePath.curve method which appears to not parse the values correctly in most cases. x + (+c1x) and y + (+c1y) evaluate to NaN often. You check for isNil, but what are you doing for cases in which it is not a number? And are you relying on implicit conversion for floats, ints etc?

@chunghe
Copy link
Contributor

chunghe commented May 31, 2016

I think this bug is in following lines:

https://github.com/magicismight/react-native-svg/blob/6ccb9058fec65d35524c874b0f2040855ad9a875/lib/SerializablePath.js#L20

the minimum code to reproduce:

"c.202.187.306.432.312.68"
  .replace(/(\.[\d]+)(\-?\.)/ig, '$1,$2')  // "c.202,.187.306,.432.312,.68"
  .match(/[a-df-z]|[\-+]?(?:[\d\.]e[\-+]?|[^\s\-+,a-z])+/ig); // ["c", ".202", ".187.306", ".432.312", ".68"]

after parsing, the array contains two points like '.187.306' which cannot covert to a number.

Hope that's helpful.

@chunghe
Copy link
Contributor

chunghe commented May 31, 2016

i've created a very simple script to solve this: https://gist.github.com/chunghe/8472c99f12beaf93fef41f30e7338d62

Replace the parser above written in Regex with svg-path-parser which is more robust and works perfectly.

@chunghe
Copy link
Contributor

chunghe commented Jun 1, 2016

@magicismight i'm not sure using 3rd-party svg path parser is the way you want to go, if yes, i could try to come up with the pull request.

@magicismight
Copy link
Collaborator

@chunghe
I don`t think 3rd-party parser is necessary.
I had fixed this by fixing the float RegExp.

.replace(/(\.\d+)(?=\-?\.)/ig, '$1,')

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

No branches or pull requests

3 participants