couchbaselabs / couchbaselabs/node-ottoman

StringType enum option allows passing "undefined" and undefined

Open
#801 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
TypeScript
Stars
295
Forks
99
PR merge metrics
No merged PRs in 30d

Description

ottoman version: 2.5.2

[StringType](https://ottomanjs.com/docs/api/classes/StringType) enum option allows passing `"undefined"` and `undefined`.

It also sets the value to `"undefined"`.

When constructing the document, `undefined` will be cast to `"undefined"`.

When saving the document, `"undefined"` will pass the check here:

https://github.com/couchbaselabs/node-ottoman/blob/f205b2c60146abe04165e78659c16ce0d15a4164/src/schema/types/string-type.ts#L262

example:

```js
import { connect, model, Schema } from "ottoman";

await connect({
bucketName: "travel-sample",
connectionString: "couchbase://localhost",
username: "Administrator",
password: "password",
});

const userSchema = new Schema({
gender: { type: String, enum: ["M", "F"] },
});

const User = model("User", userSchema, {
scopeName: "_default",
collectionName: "_default",
});

const a = new User({ gender: undefined });
await a.save();
console.log(a.gender === "undefined"); // got true, expected false

const aa = await User.findById(a.id);
console.log(aa.gender === "undefined"); // got true, expected false

const b = new User({ gender: "undefined" });
await b.save(); // passes, expected ValidationError
console.log(b.gender === "undefined"); // got true, expected false

const bb = await User.findById(b.id);
console.log(bb.gender === "undefined"); // got true, expected false
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in src/schema/types/string-type.ts at the validation logic linked in the report, and reproduce the provided constructor and save examples. Done means undefined is not converted to the string "undefined", and the literal "undefined" is rejected for the enum option with the expected validation behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
nodejs, typescript
Domain
backend, database
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.