Skip to content

Commit

Permalink
Cleanup for #1510.
Browse files Browse the repository at this point in the history
  • Loading branch information
Marsup committed Jun 29, 2018
1 parent 8b39221 commit bcc5f12
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
5 changes: 4 additions & 1 deletion API.md
Expand Up @@ -2101,10 +2101,13 @@ paddingOptionalSchema.validate('VE9PTUFOWVNFQ1JFVFM'); // No Error
paddingOptionalSchema.validate('VE9PTUFOWVNFQ1JFVFM='); // No Error
```

#### `string.dataUri()`
#### `string.dataUri([options])`

Requires the string value to be a valid data URI string.

- `options` - optional settings:
- `paddingRequired` - optional parameter defaulting to `true` which will require `=` padding if `true` or make padding optional if `false`.

```js
const schema = Joi.string().dataUri();
schema.validate('VE9PTUFOWVNFQ1JFVFM='); // ValidationError: "value" must be a valid dataUri string
Expand Down
19 changes: 12 additions & 7 deletions lib/types/string/index.js
Expand Up @@ -485,13 +485,18 @@ internals.String = class extends Any {

const matches = value.match(regex);

if (matches &&
matches[2] === 'base64' &&
base64regex.test(matches[3])) {
return value;
}
else if (matches && (!matches[2] || matches[2] !== 'base64')) {
return value;
if (matches) {
if (!matches[2]) {
return value;
}

if (matches[2] !== 'base64') {
return value;
}

if (base64regex.test(matches[3])) {
return value;
}
}

return this.createError('string.dataUri', { value }, state, options);
Expand Down

0 comments on commit bcc5f12

Please sign in to comment.