[swift-users] I ve found a serious Bug in JSONEncoder (SR-6131) and would like to fix it.

2017-12-18 Thread Benoit Pereira da silva via swift-users
Dear all

I've found a serious Bug in JSONEncoder SR-6131 
 and would like to fix it.
This bug cause JSON encoding issues on Double when using a local that does not 
use dot as decimal separator e.g « fr_FR » (we use a coma)

Demonstration of the issue : 

import Foundation

// Required to call setLocale
import Darwin

// Let's set to french
setlocale(LC_ALL,"fr_FR")
 
struct Shot:Codable{
let seconds:Double
}
 
let shot = Shot(seconds: 1.1)
 
do{
let data = try JSONEncoder().encode(shot)
if let json =  String(data:data, encoding:.utf8){
// the result is : "{"seconds":1,1001}"
// The decimal separator should not be "," but "."
print(json)
}
}catch{
print("\(error)")
}
 
exit(EX_OK)




I would like to propose my fix, test it and, but i’m not mastering the 
contribution mechanism.

Where should i start? 

I ve forked 
https://github.com/benoit-pereira-da-silva/swift-corelibs-foundation 

I have a very simple Unit test that demonstrates the issue.

How can i test my 


Thanks





Benoit Pereira da Silva
Ultra Mobile Developer & Movement Activist
Développeur Ultra Mobile & Militant du mouvement
https://pereira-da-silva.com 





✄ 
This e-mail is confidential. Distribution, copy, publication or use of this 
information for any purpose is prohibited without agreement of the sender.
Ce message est confidentiel. Toute distribution, copie, publication ou usage 
des informations contenues dans ce message sont interdits sans agrément 
préalable de l'expéditeur.



___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


[swift-users] I've found a serious Bug in JSON encoding (SR-6631) and would like to fix it. [Sorry for the multiple posts]

2017-12-18 Thread Benoit Pereira da silva via swift-users
Dear all

I've found a serious Bug in the JSON encoding foundations. [ SR-6631 
 ]

This bug cause JSON encoding issues on Doubles when using a locale that does 
not use dot as decimal separator e.g « fr_FR » (we use a coma)
When using such a locale JSONEncoder & JSONSerialization encodes the Double 
value with the localized decimal separator. 

Code proof of the issue : 

import Foundation

// Required to call setLocale
import Darwin

// Let's set to french
setlocale(LC_ALL,"fr_FR")
 
struct Shot:Codable{
let seconds:Double
}
 
let shot = Shot(seconds: 1.1)
 
do{
let data = try JSONEncoder().encode(shot)
if let json =  String(data:data, encoding:.utf8){
// the result is : "{"seconds":1,1001} »
// should be : "{"seconds":1.1001} »
// The decimal separator should not be "," but "."
print(json)
}
}catch{
print("\(error)")
}
 
exit(EX_OK)


Fix Proposal : 

 in swift-corelibs-foundation 
https://github.com/benoit-pereira-da-silva/swift-corelibs-foundation/blob/7bf5fc770471bcc6f9050cbdcd49492feccda2f2/Foundation/JSONSerialization.swift#L308
 

In `JSONSerialization.swift` line 308  may be should we specify  
`kCFNumberFormatterDecimalSeparator` ? 
Adding :  CFNumberFormatterSetProperty(formatter, 
kCFNumberFormatterDecimalSeparator,CFSTR("."))

private lazy var _numberformatter: CFNumberFormatter = {
let formatter: CFNumberFormatter
formatter = CFNumberFormatterCreate(nil, CFLocaleCopyCurrent(), 
kCFNumberFormatterNoStyle)
CFNumberFormatterSetProperty(formatter, 
kCFNumberFormatterMaxFractionDigits, NSNumber(value: 15))
CFNumberFormatterSetProperty(formatter, 
kCFNumberFormatterDecimalSeparator,CFSTR("."))
CFNumberFormatterSetFormat(formatter, "0.###"._cfObject)
return formatter
}()


I would like to propose my fix, test it and, but i’m not mastering the 
contribution mechanism.

Where should i start? 

I ve forked swift-corelibs-foundation 

How can i test my fix? 




Thanks



Benoit Pereira da Silva
Ultra Mobile Developer & Movement Activist
Développeur Ultra Mobile & Militant du mouvement
https://pereira-da-silva.com 





✄ 
This e-mail is confidential. Distribution, copy, publication or use of this 
information for any purpose is prohibited without agreement of the sender.
Ce message est confidentiel. Toute distribution, copie, publication ou usage 
des informations contenues dans ce message sont interdits sans agrément 
préalable de l'expéditeur.



___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


[swift-users] I ve found a serious Bug in JSONEncoder (SR-6131) and would like to fix it.

2017-12-18 Thread Benoit Pereira da silva via swift-users
Dear all

I've found a serious Bug in JSONEncoder SR-6131 
 and would like to fix it.
This bug cause JSON encoding issues on Double when using a local that does not 
use dot as decimal separator e.g « fr_FR » (we use a coma)

Demonstration of the issue : 

import Foundation

// Required to call setLocale
import Darwin

// Let's set to french
setlocale(LC_ALL,"fr_FR")
 
struct Shot:Codable{
let seconds:Double
}
 
let shot = Shot(seconds: 1.1)
 
do{
let data = try JSONEncoder().encode(shot)
if let json =  String(data:data, encoding:.utf8){
// the result is : "{"seconds":1,1001} »
// should be : "{"seconds":1.1001} »
// The decimal separator should not be "," but "."
print(json)
}
}catch{
print("\(error)")
}
 
exit(EX_OK)




I would like to propose my fix, test it and, but i’m not mastering the 
contribution mechanism.

Where should i start? 

I ve forked 
https://github.com/benoit-pereira-da-silva/swift-corelibs-foundation 

I have a very simple Unit test that demonstrates the issue.

How can i test my 


Thanks





Benoit Pereira da Silva
Ultra Mobile Developer & Movement Activist
Développeur Ultra Mobile & Militant du mouvement
https://pereira-da-silva.com 





✄ 
This e-mail is confidential. Distribution, copy, publication or use of this 
information for any purpose is prohibited without agreement of the sender.
Ce message est confidentiel. Toute distribution, copie, publication ou usage 
des informations contenues dans ce message sont interdits sans agrément 
préalable de l’expéditeur.


___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users