client_side_validations 11.1.3 → 12.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bb05711ee69d3edec166fdb2e15b5478a865f7c2952b88d169d5517089a4d2c7
4
- data.tar.gz: c522d25ac8c086a9718308a98f1524b9c937b2b795fd3a0f47a78d21470e55a9
3
+ metadata.gz: 3363fadd705aaa2465892b932a0c12c0d39b3281cb513db4a995bb1f2f6014e5
4
+ data.tar.gz: 1e307e3dffee20217b2d2b1860f6d3d2ef51cdd9cefc6a1a35081af51ae47451
5
5
  SHA512:
6
- metadata.gz: e896daa042d1266d87d459bb97f6c21536d7f94e19cea43f238f548eaaa8020255842e6b6ec8901d21a25187e9ca4d88b91cb64357063f7a9efac476aa8eaad4
7
- data.tar.gz: 28deac80645181f6cd01efd510bb14409d5fe220a789bba7300ae5c70d2af7d74260a5ecfa46d8f130711eb1f01a7437e5652c27fdbe30b40ca8e805d48eb28e
6
+ metadata.gz: a01830948811607a0bc6edbbb097d33ab9e36926f3fef83f7e1ea6b7a0b70e76a48a8e2bf8e3b5497a35ba8fa7e24fa2f8a6c35c9d966eb353ff1904112d0023
7
+ data.tar.gz: ef4cf650a6a33552a189436a502aa16ed878b761554c43198117be63a0192d7f31e2c28a5f7f8b3155798eda2b6015196b22f5730e7a390753a0cd6d9896e36e
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 12.0.0 / 2018-12-12
4
+
5
+ * [FEATURE] Drop the deprecated tokenizer support in length validator
6
+ * [ENHANCEMENT] Do not use `New Function` ([#733](https://github.com/DavyJonesLocker/client_side_validations/issues/733))
7
+ * [ENHANCEMENT] Remove 'g' flag from RegExp conversions ([#750](https://github.com/DavyJonesLocker/client_side_validations/issues/750))
8
+ * [ENHANCEMENT] Update dependencies
9
+
3
10
  ## 11.1.3 / 2018-09-08
4
11
 
5
12
  * [ENHANCEMENT] Test against jQuery 3.3.1 by default
@@ -24,7 +24,7 @@ module ClientSideValidations
24
24
 
25
25
  def client_side_form_settings(_options, form_helper)
26
26
  {
27
- type: self.class.to_s,
27
+ type: self.class.to_s,
28
28
  input_tag: form_helper.class.field_error_proc.call(%(<span id="input_tag" />), Struct.new(:error_message, :tag_id).new([], '')),
29
29
  label_tag: form_helper.class.field_error_proc.call(%(<label id="label_tag" />), Struct.new(:error_message, :tag_id).new([], ''))
30
30
  }
@@ -14,6 +14,7 @@ module ClientSideValidations
14
14
  # to inject the csv options in a data attribute in a clean way.
15
15
  # So we basically reimplement the whole form_for method
16
16
  raise ArgumentError, 'Missing block' unless block_given?
17
+
17
18
  html_options = options[:html] ||= {}
18
19
 
19
20
  # Moving the switch statement to another method to
@@ -58,6 +59,7 @@ module ClientSideValidations
58
59
  else
59
60
  object = record.is_a?(Array) ? record.last : record
60
61
  raise ArgumentError, 'First argument in form cannot contain nil or be empty' unless object
62
+
61
63
  object_name = options[:as] || model_name_from_record_or_class(object).param_key
62
64
  apply_form_for_options!(record, object, options)
63
65
  end
@@ -133,7 +135,7 @@ module ClientSideValidations
133
135
  csv_options = {
134
136
  html_settings: builder.client_side_form_settings(options, self),
135
137
  number_format: number_format,
136
- validators: construct_validators
138
+ validators: construct_validators
137
139
  }
138
140
 
139
141
  html_options['data-client-side-validations'] = csv_options.to_json
@@ -105,6 +105,7 @@ module ClientSideValidations
105
105
 
106
106
  def validator_turned_off?(attr, validator, force)
107
107
  return true if ::ClientSideValidations::Config.disabled_validators.include?(validator.kind)
108
+
108
109
  case force
109
110
  when FalseClass
110
111
  true
@@ -147,6 +148,7 @@ module ClientSideValidations
147
148
 
148
149
  if options[:in].respond_to?(:call)
149
150
  return unless force
151
+
150
152
  options[:in] = options[:in].call(model)
151
153
  end
152
154
 
@@ -7,10 +7,12 @@ module ClientSideValidations
7
7
  options = self.options.dup
8
8
  if options[:with].respond_to?(:call)
9
9
  return unless force
10
+
10
11
  options[:with] = options[:with].call(model)
11
12
  build_client_side_hash(model, attribute, options)
12
13
  elsif options[:without].respond_to?(:call)
13
14
  return unless force
15
+
14
16
  options[:without] = options[:without].call(model)
15
17
  build_client_side_hash(model, attribute, options)
16
18
  else
@@ -26,8 +26,7 @@ module ClientSideValidations
26
26
 
27
27
  def options_hash(options)
28
28
  hash = { messages: {} }
29
- hash[:js_tokenizer] = options[:js_tokenizer] if options[:js_tokenizer]
30
- hash[:allow_blank] = true if options[:allow_nil] || options[:allow_blank]
29
+ hash[:allow_blank] = true if options[:allow_nil] || options[:allow_blank]
31
30
  hash
32
31
  end
33
32
  end
@@ -19,6 +19,7 @@ module ClientSideValidations
19
19
 
20
20
  if count.respond_to?(:call)
21
21
  next unless force
22
+
22
23
  count = count.call(model)
23
24
  end
24
25
 
@@ -4,7 +4,7 @@ require 'js_regex'
4
4
 
5
5
  class Regexp
6
6
  def as_json(*)
7
- JsRegex.new(self, options: 'g').to_h
7
+ JsRegex.new(self).to_h
8
8
  end
9
9
 
10
10
  def to_json(options = nil)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ClientSideValidations
4
- VERSION = '11.1.3'.freeze
4
+ VERSION = '12.0.0'.freeze
5
5
  end
@@ -5,6 +5,7 @@ module ClientSideValidations
5
5
  class CopyAssetsGenerator < Rails::Generators::Base
6
6
  def copy_javascript_asset
7
7
  return unless self.class == CopyAssetsGenerator || !asset_pipeline_enabled?
8
+
8
9
  assets.each do |asset|
9
10
  source_paths << asset[:path]
10
11
  copy_file asset[:file], "#{asset_directory}/#{asset[:file]}"
@@ -1,6 +1,6 @@
1
1
 
2
2
  /*!
3
- * Client Side Validations - v11.1.3 (https://github.com/DavyJonesLocker/client_side_validations)
3
+ * Client Side Validations - v12.0.0 (https://github.com/DavyJonesLocker/client_side_validations)
4
4
  * Copyright (c) 2018 Geremia Taglialatela, Brian Cardarella
5
5
  * Licensed under MIT (http://opensource.org/licenses/mit-license.php)
6
6
  */
@@ -363,7 +363,7 @@
363
363
  }
364
364
  },
365
365
  numericality: function(element, options) {
366
- var $form, CHECKS, check, checkValue, fn, number_format, operator, val;
366
+ var $form, NUMERICALITY_CHECKS, check, checkValue, check_function, number_format, val;
367
367
  if (options.allow_blank === true && this.presence(element, {
368
368
  message: options.messages.numericality
369
369
  })) {
@@ -378,15 +378,25 @@
378
378
  if (!ClientSideValidations.patterns.numericality["default"].test(val)) {
379
379
  return options.messages.numericality;
380
380
  }
381
- CHECKS = {
382
- greater_than: '>',
383
- greater_than_or_equal_to: '>=',
384
- equal_to: '==',
385
- less_than: '<',
386
- less_than_or_equal_to: '<='
381
+ NUMERICALITY_CHECKS = {
382
+ greater_than: function(a, b) {
383
+ return a > b;
384
+ },
385
+ greater_than_or_equal_to: function(a, b) {
386
+ return a >= b;
387
+ },
388
+ equal_to: function(a, b) {
389
+ return a === b;
390
+ },
391
+ less_than: function(a, b) {
392
+ return a < b;
393
+ },
394
+ less_than_or_equal_to: function(a, b) {
395
+ return a <= b;
396
+ }
387
397
  };
388
- for (check in CHECKS) {
389
- operator = CHECKS[check];
398
+ for (check in NUMERICALITY_CHECKS) {
399
+ check_function = NUMERICALITY_CHECKS[check];
390
400
  if (!(options[check] != null)) {
391
401
  continue;
392
402
  }
@@ -394,8 +404,7 @@
394
404
  if ((checkValue == null) || checkValue === '') {
395
405
  return;
396
406
  }
397
- fn = new Function("return " + val + " " + operator + " " + checkValue);
398
- if (!fn()) {
407
+ if (!check_function(parseFloat(val), parseFloat(checkValue))) {
399
408
  return options.messages[check];
400
409
  }
401
410
  }
@@ -407,13 +416,18 @@
407
416
  }
408
417
  },
409
418
  length: function(element, options) {
410
- var CHECKS, blankOptions, check, fn, message, operator, tokenized_length, tokenizer;
411
- tokenizer = options.js_tokenizer || "split('')";
412
- tokenized_length = new Function('element', "return (element.val()." + tokenizer + " || '').length")(element);
413
- CHECKS = {
414
- is: '==',
415
- minimum: '>=',
416
- maximum: '<='
419
+ var LENGTH_CHECKS, blankOptions, check, check_function, length, message;
420
+ length = element.val().length;
421
+ LENGTH_CHECKS = {
422
+ is: function(a, b) {
423
+ return a === b;
424
+ },
425
+ minimum: function(a, b) {
426
+ return a >= b;
427
+ },
428
+ maximum: function(a, b) {
429
+ return a <= b;
430
+ }
417
431
  };
418
432
  blankOptions = {};
419
433
  blankOptions.message = options.is ? options.messages.is : options.minimum ? options.messages.minimum : void 0;
@@ -424,14 +438,12 @@
424
438
  }
425
439
  return message;
426
440
  }
427
- for (check in CHECKS) {
428
- operator = CHECKS[check];
429
- if (!options[check]) {
430
- continue;
431
- }
432
- fn = new Function("return " + tokenized_length + " " + operator + " " + options[check]);
433
- if (!fn()) {
434
- return options.messages[check];
441
+ for (check in LENGTH_CHECKS) {
442
+ check_function = LENGTH_CHECKS[check];
443
+ if (options[check]) {
444
+ if (!check_function(length, parseInt(options[check]))) {
445
+ return options.messages[check];
446
+ }
435
447
  }
436
448
  }
437
449
  },
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: client_side_validations
3
3
  version: !ruby/object:Gem::Version
4
- version: 11.1.3
4
+ version: 12.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Geremia Taglialatela
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-09-08 00:00:00.000000000 Z
12
+ date: 2018-12-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -51,14 +51,14 @@ dependencies:
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '3.0'
54
+ version: '3.1'
55
55
  type: :runtime
56
56
  prerelease: false
57
57
  version_requirements: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '3.0'
61
+ version: '3.1'
62
62
  - !ruby/object:Gem::Dependency
63
63
  name: appraisal
64
64
  requirement: !ruby/object:Gem::Requirement
@@ -163,14 +163,14 @@ dependencies:
163
163
  requirements:
164
164
  - - "~>"
165
165
  - !ruby/object:Gem::Version
166
- version: 0.58.2
166
+ version: 0.61.1
167
167
  type: :development
168
168
  prerelease: false
169
169
  version_requirements: !ruby/object:Gem::Requirement
170
170
  requirements:
171
171
  - - "~>"
172
172
  - !ruby/object:Gem::Version
173
- version: 0.58.2
173
+ version: 0.61.1
174
174
  - !ruby/object:Gem::Dependency
175
175
  name: simplecov
176
176
  requirement: !ruby/object:Gem::Requirement