Skip to content

Commit 5a41331

Browse files
authored
Merge pull request #360 from fsprojects/repo-assist/fix-null-checks-insertAt-removeAt-updateAt-e5494698cb332bdb
[Repo Assist] fix: null source raises ArgumentNullException for insertAt, removeAt, updateAt
2 parents ce655c1 + 282f2d2 commit 5a41331

File tree

5 files changed

+31
-0
lines changed

5 files changed

+31
-0
lines changed

release-notes.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Release notes:
33

44
1.0.0
5+
- fixes: TaskSeq.insertAt, insertManyAt, removeAt, removeManyAt, updateAt now raise ArgumentNullException (not NullReferenceException) when given a null source; insertManyAt also validates the values argument
56
- refactor: simplify lengthBy and lengthBeforeMax to use while! and remove the redundant mutable 'go' and initial MoveNextAsync
67
- adds TaskSeq.distinctUntilChangedWith and TaskSeq.distinctUntilChangedWithAsync, #345
78
- adds TaskSeq.withCancellation, #167

src/FSharp.Control.TaskSeq.Test/TaskSeq.InsertAt.Tests.fs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@ open FSharp.Control
1616
exception SideEffectPastEnd of string
1717

1818
module EmptySeq =
19+
[<Fact>]
20+
let ``Null source is invalid`` () =
21+
assertNullArg <| fun () -> TaskSeq.insertAt 0 99 null
22+
23+
assertNullArg
24+
<| fun () -> TaskSeq.insertManyAt 0 TaskSeq.empty null
25+
26+
[<Fact>]
27+
let ``Null values argument is invalid for insertManyAt`` () =
28+
assertNullArg
29+
<| fun () -> TaskSeq.insertManyAt 0 null (TaskSeq.ofList [ 1 ])
30+
1931
[<Theory; ClassData(typeof<TestEmptyVariants>)>]
2032
let ``TaskSeq-insertAt(0) on empty input returns singleton`` variant =
2133
Gen.getEmptyVariant variant

src/FSharp.Control.TaskSeq.Test/TaskSeq.RemoveAt.Tests.fs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ open FSharp.Control
1616
exception SideEffectPastEnd of string
1717

1818
module EmptySeq =
19+
[<Fact>]
20+
let ``Null source is invalid`` () =
21+
assertNullArg <| fun () -> TaskSeq.removeAt 0 null
22+
23+
assertNullArg <| fun () -> TaskSeq.removeManyAt 0 1 null
24+
1925
[<Theory; ClassData(typeof<TestEmptyVariants>)>]
2026
let ``TaskSeq-removeAt(0) on empty input raises`` variant =
2127
fun () ->

src/FSharp.Control.TaskSeq.Test/TaskSeq.UpdateAt.Tests.fs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ open FSharp.Control
1515
exception SideEffectPastEnd of string
1616

1717
module EmptySeq =
18+
[<Fact>]
19+
let ``Null source is invalid`` () = assertNullArg <| fun () -> TaskSeq.updateAt 0 99 null
20+
1821
[<Theory; ClassData(typeof<TestEmptyVariants>)>]
1922
let ``TaskSeq-updateAt(0) on empty input should throw ArgumentException`` variant =
2023
fun () ->

src/FSharp.Control.TaskSeq/TaskSeqInternal.fs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,6 +1369,12 @@ module internal TaskSeqInternal =
13691369

13701370
/// InsertAt or InsertManyAt
13711371
let insertAt index valueOrValues (source: TaskSeq<_>) =
1372+
checkNonNull (nameof source) source
1373+
1374+
match valueOrValues with
1375+
| Many values -> checkNonNull "values" values
1376+
| One _ -> ()
1377+
13721378
raiseCannotBeNegative (nameof index) index
13731379

13741380
taskSeq {
@@ -1394,6 +1400,7 @@ module internal TaskSeqInternal =
13941400
}
13951401

13961402
let removeAt index (source: TaskSeq<'T>) =
1403+
checkNonNull (nameof source) source
13971404
raiseCannotBeNegative (nameof index) index
13981405

13991406
taskSeq {
@@ -1411,6 +1418,7 @@ module internal TaskSeqInternal =
14111418
}
14121419

14131420
let removeManyAt index count (source: TaskSeq<'T>) =
1421+
checkNonNull (nameof source) source
14141422
raiseCannotBeNegative (nameof index) index
14151423

14161424
taskSeq {
@@ -1429,6 +1437,7 @@ module internal TaskSeqInternal =
14291437
}
14301438

14311439
let updateAt index value (source: TaskSeq<'T>) =
1440+
checkNonNull (nameof source) source
14321441
raiseCannotBeNegative (nameof index) index
14331442

14341443
taskSeq {

0 commit comments

Comments
 (0)