Skip to content

Commit

Permalink
adding a protective check for builtin string functions
Browse files Browse the repository at this point in the history
  • Loading branch information
shaselton-usds committed Aug 2, 2024
1 parent 0b0a25a commit c425677
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/versions/common/csv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,5 +140,6 @@ export function isValidDate(value: string) {
}

export function matchesString(value: string, target: string) {
if(typeof value !== 'string') return false
return value.trim().toLocaleUpperCase() === target.trim().toLocaleUpperCase()
}
9 changes: 8 additions & 1 deletion test/common/csv.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from "ava"
import { csvColumnName } from "../../src/versions/common/csv.js"
import { csvColumnName, matchesString } from "../../src/versions/common/csv.js"

test("csvColumnName", (t) => {
t.is(csvColumnName(0), "A")
Expand All @@ -8,3 +8,10 @@ test("csvColumnName", (t) => {
t.is(csvColumnName(18278), "AAAA")
t.is(csvColumnName(475254), "AAAAA")
})

test("matchesString", (t) => {
t.is(matchesString("testing", "testing"), true)
t.is(matchesString("testing", "tresting"), false)
t.is(matchesString(1 as unknown as string, "testing"), false)
t.is(matchesString(undefined as unknown as string, "testing"), false)
})

0 comments on commit c425677

Please sign in to comment.