CodeSOD: Validation Trimmed Away
thedailywtf.com·23h
Format Validation
Preview
Report Post

Grace sends us, in her words, "the function that validates the data from the signup form for a cursed application."

It’s more than one function, but there are certainly some clearly cursed aspects of the whole thing.

function trimStr(v) {
return typeof v === "string" ? v.trim() : v;
}

This function, itself, isn’t cursed, but it certainly represents a bad omen. Take any type of input, and if that input happens to be a string, return the trimmed version. Otherwise, return the input unchanged. I’ve got good news and bad news about this omen: the good news is that it isn’t used in most of the code that follows, and the bad news is that it is used in some of the code that follows.

The next function builds a validation schema using the yup library, and we’ll take …

Similar Posts

Loading similar posts...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help