File tree Expand file tree Collapse file tree 4 files changed +25
-8
lines changed
cedar-lean/Cedar/Spec/Ext Expand file tree Collapse file tree 4 files changed +25
-8
lines changed Original file line number Diff line number Diff line change 1515-/
1616
1717import Cedar.Data.Int64
18+ import Cedar.Spec.Ext.Util
1819import Std.Time
1920import Std.Time.Format
2021
@@ -227,7 +228,7 @@ def parseUnit? (isNegative : Bool) (str : String) (suffix : String) : Option (In
227228 if digits.isEmpty
228229 then none
229230 else do
230- let nUnsignedUnits ← String. toNat? (String.ofList digits)
231+ let nUnsignedUnits ← toNat?' (String.ofList digits)
231232 let units ← if isNegative
232233 then durationUnits? (Int.negOfNat nUnsignedUnits) suffix
233234 else durationUnits? (Int.ofNat nUnsignedUnits) suffix
Original file line number Diff line number Diff line change 1515-/
1616
1717import Cedar.Data.Int64
18+ import Cedar.Spec.Ext.Util
1819
1920/-! This file defines Cedar decimal values and functions. -/
2021
@@ -48,11 +49,7 @@ def parse (str : String) : Option Decimal :=
4849 let rlen := right.length
4950 if 0 < rlen ∧ rlen ≤ DECIMAL_DIGITS
5051 then
51- -- String.toInt? has undocumented behavior (well, undocumented as of this writing)
52- -- that it allows `_` characters in certain positions in the representation of an
53- -- integer. We want to disallow strings with `_` characters per the Cedar spec.
54- if left.contains '_' ∨ right.contains '_' then .none else
55- match String.toInt? left, String.toNat? right with
52+ match toInt?' left, toNat?' right with
5653 | .some l, .some r =>
5754 let l' := l * (Int.pow 10 DECIMAL_DIGITS)
5855 let r' := r * (Int.pow 10 (DECIMAL_DIGITS - rlen))
Original file line number Diff line number Diff line change 1414 limitations under the License.
1515-/
1616
17+ import Cedar.Spec.Ext.Util
18+
1719/-! This file defines Cedar IpAddr values and functions. -/
1820
1921namespace Cedar.Spec.Ext
@@ -136,15 +138,15 @@ private def parsePrefixNat (str : String) (digits : Nat) (size : Nat) : Option (
136138 let len := str.length
137139 if 0 < len && len ≤ digits && (str.startsWith "0" → str = "0" )
138140 then do
139- let n ← str. toNat?
141+ let n ← toNat?' str
140142 if n ≤ size then .some (Fin.ofNat (size+1 ) n) else .none
141143 else .none
142144
143145private def parseNumV4 (str : String) : Option (BitVec 8 ) :=
144146 let len := str.length
145147 if 0 < len && len ≤ 3 && (str.startsWith "0" → str = "0" )
146148 then do
147- let n ← str. toNat?
149+ let n ← toNat?' str
148150 if n ≤ 0xff then .some n else .none
149151 else .none
150152
Original file line number Diff line number Diff line change 1+ namespace Cedar.Spec.Ext
2+
3+ ----- Helper Functions -----
4+
5+ /--
6+ Helper function that wraps String.toInt? but returns .none if the string contains '_'.
7+ This prevents the undocumented behavior where String.toInt? allows '_' characters.
8+ -/
9+ def toInt?' (str : String) : Option Int :=
10+ if str.contains '_' then .none else String.toInt? str
11+
12+ /--
13+ Helper function that wraps String.toNat? but returns .none if the string contains '_'.
14+ This prevents the undocumented behavior where String.toNat? allows '_' characters.
15+ -/
16+ def toNat?' (str : String) : Option Nat :=
17+ if str.contains '_' then .none else String.toNat? str
You can’t perform that action at this time.
0 commit comments