You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm working on a project that involves cryptographic signature verification on JSON files, but I'm experiencing some issues trying to get JSON files sorted as I need them. I need the JSON files to have all keys be sorted both alphabetically and numerically so I'm using the .sortedKeys option in JSONSerialization to do this. I am able to sort all keys alphabetically but not numerically although I believe that .sortedKeys should do both. I'm basing my judgement off of the following implementation at https://github.com/apple/swift-corelibs-foundation/blob/master/Foundation/JSONSerialization.swift#L531-L546
*I have taken these two examples from the signed_root.json and the extracted_signed_root.json files that I have attached to this issue
I was wondering if there's a chance that the .sortedKeys I'm using is not what I see in the implementation or if there may be a bug of some kind where .sortedKeys doesn't sort numerically. Any clarification would be greatly appreciated.
The text was updated successfully, but these errors were encountered:
Looks like a swift-corelibs-foundation issue. You can see from the linked JSONSerialization code that we do supply the .numeric option, but it looks like it might not be respected. Going to take a look.
Scratch that, this behaves correctly. Numeric search is being respected — it so happens that 0501a2a51fa40da53ad9739e95456859fb81d4c5bce9c4b831149eb37817a5e5 begins with the number 0501 (501), while 1b729c9ed9df962ac85c78742f973b5a63613693d093898dc5b6fae811f3e583 starts with the number 1. Since 1 < 501, it's being sorted to the front. The numeric sorting is correct here; it's just that seeing the leading 0 can be misleading.
Attachment: Download
Additional Detail from JIRA
md5: db8160e82be8474efdf89e355ba18938
Issue Description:
I'm working on a project that involves cryptographic signature verification on JSON files, but I'm experiencing some issues trying to get JSON files sorted as I need them. I need the JSON files to have all keys be sorted both alphabetically and numerically so I'm using the .sortedKeys option in JSONSerialization to do this. I am able to sort all keys alphabetically but not numerically although I believe that .sortedKeys should do both. I'm basing my judgement off of the following implementation at https://github.com/apple/swift-corelibs-foundation/blob/master/Foundation/JSONSerialization.swift#L531-L546
Since this implementation uses the .numeric option, I would assume that .sortedKeys should sort keys numerically although it doesn't appear to do so.
Here is an example
This is how I call .sortedKeys
I need to achieve the following sorting:
But .sortedKeys gives me this sorting:
*I have taken these two examples from the signed_root.json and the extracted_signed_root.json files that I have attached to this issue
I was wondering if there's a chance that the .sortedKeys I'm using is not what I see in the implementation or if there may be a bug of some kind where .sortedKeys doesn't sort numerically. Any clarification would be greatly appreciated.
The text was updated successfully, but these errors were encountered: