<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class="">Dear all</div><div class=""><br class=""></div><div class="">I've found a serious Bug in the JSON encoding foundations. [&nbsp;<a href="https://bugs.swift.org/browse/SR-6631" class="">SR-6631</a>&nbsp;]</div><div class=""><br class=""></div><div class="">This bug cause JSON encoding issues on Doubles when using a locale that does not use dot as decimal separator e.g «&nbsp;fr_FR&nbsp;» (we use a coma)</div><div class="">When using such a locale JSONEncoder &amp; JSONSerialization encodes the Double value with the localized decimal separator.&nbsp;</div><div class=""><br class=""></div><div class=""><b class="">Code proof of the issue :&nbsp;</b></div><div class=""><br class=""></div><div class=""><pre class="code-java" style="margin-top: 0px; margin-bottom: 0px; padding: 0px; max-height: 30em; overflow: auto; white-space: pre-wrap; word-wrap: normal; color: rgb(51, 51, 51); font-size: 11px;"><span class="code-keyword" style="color: rgb(0, 0, 145);">import</span> Foundation

<span class="code-comment" style="color: rgb(128, 128, 128);">// Required to call setLocale
</span><span class="code-keyword" style="color: rgb(0, 0, 145);">import</span> Darwin

<span class="code-comment" style="color: rgb(128, 128, 128);">// Let's set to french
</span>setlocale(LC_ALL,<span class="code-quote" style="color: rgb(0, 145, 0);">"fr_FR"</span>)
&nbsp;
struct Shot:Codable{
&nbsp; &nbsp; let seconds:<span class="code-object" style="color: rgb(145, 0, 145);">Double</span>
}
&nbsp;
let shot = Shot(seconds: 1.1)
&nbsp;
<span class="code-keyword" style="color: rgb(0, 0, 145);">do</span>{
&nbsp; &nbsp; let data = <span class="code-keyword" style="color: rgb(0, 0, 145);">try</span> JSONEncoder().encode(shot)
&nbsp; &nbsp; <span class="code-keyword" style="color: rgb(0, 0, 145);">if</span> let json =&nbsp; <span class="code-object" style="color: rgb(145, 0, 145);">String</span>(data:data, encoding:.utf8){
&nbsp; &nbsp; &nbsp; &nbsp; <span class="code-comment" style="color: rgb(128, 128, 128);">// the result is : <span class="code-quote">"{"</span>seconds<span class="code-quote">":1,1000000000000001}&nbsp;»</span></span></pre><pre class="code-java" style="margin-top: 0px; margin-bottom: 0px; padding: 0px; max-height: 30em; overflow: auto; white-space: pre-wrap; word-wrap: normal; color: rgb(51, 51, 51); font-size: 11px;"><span class="code-comment" style="color: rgb(128, 128, 128);"><span class="Apple-tab-span" style="white-space: pre;">        </span>// should be : <span class="code-quote">"{"</span>seconds<span class="code-quote">":1.1000000000000001}&nbsp;»</span>
</span>&nbsp; &nbsp; &nbsp; &nbsp; <span class="code-comment" style="color: rgb(128, 128, 128);">// The decimal separator should not be <span class="code-quote">","</span> but <span class="code-quote">"."</span>
</span>&nbsp; &nbsp; &nbsp; &nbsp; print(json)
&nbsp; &nbsp; }
}<span class="code-keyword" style="color: rgb(0, 0, 145);">catch</span>{
&nbsp; &nbsp; print(<span class="code-quote" style="color: rgb(0, 145, 0);">"\(error)"</span>)
}
&nbsp;
exit(EX_OK)</pre><div class=""><br class=""></div></div><div class=""><br class=""></div><div class=""><b class="">Fix Proposal :&nbsp;</b></div><div class=""><br class=""></div><div class="">&nbsp;in swift-corelibs-foundation&nbsp;<a href="https://github.com/benoit-pereira-da-silva/swift-corelibs-foundation/blob/7bf5fc770471bcc6f9050cbdcd49492feccda2f2/Foundation/JSONSerialization.swift#L308" class="">https://github.com/benoit-pereira-da-silva/swift-corelibs-foundation/blob/7bf5fc770471bcc6f9050cbdcd49492feccda2f2/Foundation/JSONSerialization.swift#L308</a></div><div class="">In `JSONSerialization.swift` line 308 &nbsp;may be should we specify &nbsp;`kCFNumberFormatterDecimalSeparator` ?&nbsp;</div><div class="">Adding :&nbsp;<span style="color: rgb(51, 51, 51); white-space: pre-wrap;" class=""> CFNumberFormatterSetProperty(formatter, kCFNumberFormatterDecimalSeparator,CFSTR(</span><span class="code-quote" style="white-space: pre-wrap; color: rgb(0, 145, 0);">"."</span><span style="color: rgb(51, 51, 51); white-space: pre-wrap;" class="">))</span></div><div class=""><br class=""></div><div class=""><div class="panel code" style="margin: 9px 0px; padding: 0px; border: 1px solid rgb(204, 204, 204); background-color: rgb(245, 245, 245); line-height: 1.33333333333333; font-family: monospace; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; color: rgb(51, 51, 51);"><div class="codeContent panelContent" style="margin: 0px; padding: 9px 12px;"><pre class="code-java" style="margin-top: 0px; margin-bottom: 0px; padding: 0px; max-height: 30em; overflow: auto; white-space: pre-wrap; word-wrap: normal;">&nbsp; &nbsp;&nbsp;<span class="code-keyword" style="color: rgb(0, 0, 145);">private</span> lazy <span class="code-keyword" style="color: rgb(0, 0, 145);">var</span> _numberformatter: CFNumberFormatter = {
&nbsp; &nbsp; &nbsp; &nbsp; let formatter: CFNumberFormatter
&nbsp; &nbsp; &nbsp; &nbsp; formatter = CFNumberFormatterCreate(nil, CFLocaleCopyCurrent(), kCFNumberFormatterNoStyle)
&nbsp; &nbsp; &nbsp; &nbsp; CFNumberFormatterSetProperty(formatter, kCFNumberFormatterMaxFractionDigits, NSNumber(value: 15))
&nbsp; &nbsp; &nbsp; &nbsp; CFNumberFormatterSetProperty(formatter, kCFNumberFormatterDecimalSeparator,CFSTR(<span class="code-quote" style="color: rgb(0, 145, 0);">"."</span>))<span class="code-comment" style="color: rgb(128, 128, 128);">
</span>&nbsp; &nbsp; &nbsp; &nbsp; CFNumberFormatterSetFormat(formatter, <span class="code-quote" style="color: rgb(0, 145, 0);">"0.###############"</span>._cfObject)
&nbsp; &nbsp; &nbsp; &nbsp; <span class="code-keyword" style="color: rgb(0, 0, 145);">return</span> formatter
&nbsp; &nbsp; }()</pre></div></div></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">I would like to propose my fix, test it and, but i’m not mastering the contribution mechanism.</div><div class=""><br class=""></div><div class="">Where should i start?&nbsp;</div><div class=""><br class=""></div><div class="">I ve forked&nbsp;<a href="https://github.com/benoit-pereira-da-silva/swift-corelibs-foundation/blob/7bf5fc770471bcc6f9050cbdcd49492feccda2f2/Foundation/JSONSerialization.swift#L308" class="">swift-corelibs-foundation</a></div><div class="">How can i test my fix?&nbsp;</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Thanks</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">
<div style="color: rgb(0, 0, 0); font-variant-ligatures: normal; font-variant-position: normal; font-variant-caps: normal; font-variant-numeric: normal; font-variant-alternates: normal; font-variant-east-asian: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; font-size: 14px;" class=""><div apple-content-edited="true" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span style="font-size: 12px; line-height: normal; orphans: 2; widows: 2;" class=""><font face="HelveticaNeue-Light" class=""><div style="orphans: auto; widows: auto; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal;" class=""><b class="">Benoit Pereira da Silva</b></div><div style="margin: 0px; line-height: normal;" class="">Ultra Mobile Developer &amp; Movement Activist</div><div style="margin: 0px; line-height: normal;" class="">Développeur Ultra Mobile &amp; Militant du mouvement</div><div style="margin: 0px; line-height: normal;" class=""><a href="https://pereira-da-silva.com/" class="">https://pereira-da-silva.com</a></div><div style="margin: 0px; line-height: normal;" class=""><span style="line-height: normal;" class=""></span></div></div></div><div style="orphans: auto; widows: auto; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span class=""></span></div></font></span></div></div></div></div></div></div><span style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-ligatures: normal; font-variant-position: normal; font-variant-caps: normal; font-variant-numeric: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class="Apple-interchange-newline" style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; font-variant-ligatures: normal; font-variant-position: normal; font-variant-numeric: normal; font-variant-alternates: normal; font-variant-east-asian: normal;"><span style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; font-variant-ligatures: normal; font-variant-position: normal; font-variant-numeric: normal; font-variant-alternates: normal; font-variant-east-asian: normal;"><span><span><span><span><span><span><span><span><img apple-inline="yes" id="F09A2FA7-C981-4E0E-B53D-F7C038DBBC12" src="cid:E3AF4CA8-D774-47D1-AF27-2B086409AEED@home" class=""></span><div style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; font-variant-ligatures: normal; font-variant-position: normal; font-variant-numeric: normal; font-variant-alternates: normal; font-variant-east-asian: normal;" class=""><span style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-ligatures: normal; font-variant-position: normal; font-variant-caps: normal; font-variant-numeric: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-ligatures: normal; font-variant-position: normal; font-variant-caps: normal; font-variant-numeric: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span><span><br class="Apple-interchange-newline"><br class="Apple-interchange-newline"><br class=""></span></span></span></span></div><div style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; font-variant-ligatures: normal; font-variant-position: normal; font-variant-numeric: normal; font-variant-alternates: normal; font-variant-east-asian: normal;" class=""><span style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-ligatures: normal; font-variant-position: normal; font-variant-caps: normal; font-variant-numeric: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-ligatures: normal; font-variant-position: normal; font-variant-caps: normal; font-variant-numeric: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span><span><div style="font-family: HelveticaNeue-Light; orphans: 2; widows: 2;" class=""><div class=""><span style="orphans: auto; widows: auto; background-color: rgb(255, 255, 255);" class="">✄&nbsp;--------------------------------</span><br style="orphans: auto; widows: auto;" class=""><font size="1" style="orphans: auto; widows: auto;" class="">This e-mail is confidential. Distribution, copy, publication or use of this information for any purpose is prohibited without agreement of the sender.<br class="">Ce message est confidentiel. Toute distribution, copie, publication ou usage des informations contenues dans ce message sont interdits sans agrément préalable&nbsp;de l'expéditeur.</font><br style="orphans: auto; widows: auto;" class=""></div></div></span></span></span></span></div><br class="Apple-interchange-newline" style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; font-variant-ligatures: normal; font-variant-position: normal; font-variant-numeric: normal; font-variant-alternates: normal; font-variant-east-asian: normal;"><br class="Apple-interchange-newline" style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; font-variant-ligatures: normal; font-variant-position: normal; font-variant-numeric: normal; font-variant-alternates: normal; font-variant-east-asian: normal;">
</span></span></span></span></span></span></span></span></span></div>
<br class=""></body></html>