Skip to content

Commit f2db06a

Browse files
committed
fix: regex rule,messages ordering
1 parent f0921f3 commit f2db06a

File tree

6 files changed

+34
-9
lines changed

6 files changed

+34
-9
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,22 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [4.3.3]
9+
10+
### Fixed
11+
12+
- message ordering
13+
14+
### Changed
15+
16+
- regex rule now accepts flags
17+
18+
## [4.3.2]
19+
20+
### Fixed
21+
22+
- url rule breaks with non string value (issues/43)
23+
824
## [4.3.1]
925

1026
### Added

lib/rules/creditCard.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const v = require('validator');
22

3-
43
module.exports = function creditCard({ value }) {
54
if (v.isCreditCard(String(value))) {
65
return true;

lib/rules/regex.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
21
module.exports = function regex({ value, args }) {
3-
const [pattren] = args;
4-
const regexp = new RegExp(pattren);
2+
const [pattren, flags] = args;
3+
const regexp = new RegExp(pattren, flags);
54

65
if (!regexp.test(value)) {
76
return false;

lib/rules/url.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
const v = require('validator');
22

33
module.exports = function url({ value }) {
4+
if (typeof value !== 'string') {
5+
return false;
6+
}
7+
48
return v.isURL(value);
59
};

lib/validator.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -477,16 +477,23 @@ class Validator {
477477
// check for local scope messages
478478
if (this.hasCustomMessages) {
479479
message = this.customMessages[`${attr}.${rule}`]
480-
|| this.customMessages[rule]
481-
|| this.customMessages[attr];
480+
|| this.customMessages[attr]
481+
|| this.customMessages[rule];
482+
482483
}
483484

484485
// not found in local scope, check for global scope
485486
if (!message) {
487+
// from global messages bucket
486488
messages[this.lang].$custom = messages[this.lang].$custom || {};
489+
// message.$custom['attribute.rule']
487490
message = messages[this.lang].$custom[`${attr}.${rule}`]
488-
|| messages[this.lang][rule]
489-
|| (messages[this.lang].$custom && messages[this.lang].$custom[attr]);
491+
// message.$custom.rule
492+
|| messages[this.lang].$custom[rule]
493+
// message.$custom.attr
494+
|| messages[this.lang].$custom[attr]
495+
// message.rule
496+
|| messages[this.lang][rule];
490497

491498
if (useDefaultMessage && !message) {
492499
message = defaultMessage;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-input-validator",
3-
"version": "4.3.1",
3+
"version": "4.3.3",
44
"description": "validation library for nodejs, inspired by laravel.",
55
"main": "lib/index.js",
66
"scripts": {

0 commit comments

Comments
 (0)