Altinn / altinn-studio

Next generation open source Altinn platform and applications.
https://docs.altinn.studio
BSD 3-Clause "New" or "Revised" License
115 stars 70 forks source link

Total digits implementation in c# doesn't support negative numbers #9349

Closed mirkoSekulic closed 1 year ago

mirkoSekulic commented 1 year ago

Description of the bug

TotalDigits restriction is converted to c# class as regex that doesn't allow negative numbers.

Change regexes in Altinn.Studio.DataModeling.Utils.RestrictionsHelper class so they support negative numbers. Example: Change

"^[0-9]{0,3}"

to

"^-?[0-9]{0,3}"

Enrich RestrictionHelperTests test data with negative numbers

Steps To Reproduce

Run CsharpEnd2EndGenerationTests.Convert_FromXsd_ShouldConvertToSameCSharp test with xsd that contains totalDigits restriction.

Additional Information

No response

rvessb commented 1 year ago

org/ssb

ivarne commented 1 year ago

We found this issue too. The bigger issue in my opinion is that the [RegularExpression(...)] annotations seems rather useless when the error message is displayed this way: image

Why would you even bother using a regular expression to verify that the stringified version of a decimal datatype looks like a number. decimal can never be anything else than a number.