Skip to content

Commit

Permalink
Merge pull request #2807 from FirelyTeam/fix-fhirpath-quantity-locali…
Browse files Browse the repository at this point in the history
…zation-errors

Removed decimal to string conversions that did not use invariant culture
  • Loading branch information
mmsmits authored Jun 26, 2024
2 parents 1f4fa4d + 1a23a50 commit 40904d3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/Hl7.Fhir.Base/FhirPath/Expressions/EchoVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* This file is licensed under the BSD 3-Clause license
* available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE
*/

using System.Globalization;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
Expand Down Expand Up @@ -113,7 +115,7 @@ public override StringBuilder VisitConstant(ConstantExpression expression)
case "Quantity":
if (expression.Value is P.Quantity q)
{
_result.Append($"{q?.Value}");
_result.Append(q.Value.ToString(CultureInfo.InvariantCulture));
OutputSubToken(expression.Unit);
}
else
Expand Down Expand Up @@ -298,4 +300,4 @@ public static string EchoExpression(this Expression expr)
}
}

}
}
6 changes: 4 additions & 2 deletions src/Hl7.Fhir.Base/FhirPath/Parser/Grammar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Hl7.FhirPath.Sprache;
using P = Hl7.Fhir.ElementModel.Types;
using System;
using System.Globalization;
using System.Linq;

namespace Hl7.FhirPath.Parser
Expand All @@ -24,7 +25,8 @@ private static IResult<ConstantExpression> quantityParser(IInput i)
// Note that quantities are always parsed with a unit, otherwise they would be an integer or decimal
// and the +/- are unary operators and not a part of the quantity itself.
var result = (
from val in Lexer.DecimalNumber.Select(n => $"{n}").Or(Lexer.IntegerNumber.Select(n => $"{n}")).Select(v => new SubToken(v)).Positioned()
from val in Lexer.DecimalNumber.Select(n => n.ToString(CultureInfo.InvariantCulture))
.Or(Lexer.IntegerNumber.Select(n => n.ToString(CultureInfo.InvariantCulture))).Select(v => new SubToken(v)).Positioned()
from ws in WhitespaceOrComments()
from unit in Lexer.String.Select(u => $"'{u.Replace("'", "\\'")}'").Or(Lexer.Id).Select(v => new SubToken(v).WithLeadingWS(ws)).Positioned()
select (valToken: val, unitToken: unit)
Expand Down Expand Up @@ -319,4 +321,4 @@ from wsTrailing in WhitespaceOrComments()
.Many()
.Named("Whitespace and/or comments");
}
}
}

0 comments on commit 40904d3

Please sign in to comment.