Closed (fixed)
Project:
Drupal core
Version:
7.x-dev
Component:
field system
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
14 Jul 2011 at 14:41 UTC
Updated:
8 Jul 2022 at 20:49 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
pixelmord commentedAttached is a patch that uses preg_match instead of preg_replace and checks that a "-" can only be placed at the beginning of the string representing the number.
Comment #2
marcingy commentedMoving to d8 and marking for backport.
Comment #4
pixelmord commentedLast patch was a diff relative to the number module directory, so attached is a patch relative to Drupal root of the latest 8.x-dev
Comment #5
marcingy commentedSetting needs review for the bot.
Comment #7
franzTest fails because of:
Previously, the regexp didn't test for more than one decimal point, and that check was done later. Now that the regexp detects it earlier, the error message is not the expected one.
Comment #8
franzIt's not a pretty patch, not 100% happy with it, but I think it works with minimal changes on code.
Comment #9
franzComment #10
franzComment #11
pixelmord commentedYeah you are right, I overlooked that one, because I did not look at the test.
The question is, if the user really needs that level of detail in the error message, but since it does not really hurt to be more specific, the extra message regarding the amount of decimal points might be helpful.
Comment #12
pixelmord commentedSorry did not want to change Status.
It works for me
Comment #13
franzI wouldn't mind dropping this specific error message at all, provided the tests are done for the same cases. But I lack powers to mess with it. =)
Comment #14
attiks commentedI created #1845546: Implement validation for the TypedData API to try to solve this on all levels, since there are only 10 days left, we need to figure out what needs to be done before feature freeze and what can be done later.
Comment #15
swentel commentedComment #15.0
swentel commentedcorrected a typo
Comment #16
jhedstromComment #17
yogen.prasad commentedComment #18
manjit.singhComment #19
yogen.prasad commentedComment #20
andypostWhen browser does not support html5 validation or validation disabled http://stackoverflow.com/a/3094185
Core now stores empty value silently without validation.
So better to add validation to widget or maybe "number" element additionally to browser provided
Comment #21
andypostLooks now
is_numbericcheck is enough in\Drupal\Core\Render\Element\Number::validateNumberHere's a test to make sure that "20-40" is now checked fine
Comment #22
andypostHere's a test that proves that decimal item by-passes validation
Comment #23
andypostComment #25
deepakaryan1988Removing sprint weekend tag!!
As suggested by @YesCT
Comment #26
rpayanmComment #27
swentel commentedIsn't decimal fine because the datatype is a string ?
Comment #28
swentel commentedOh woops, didn't look at the schema, ignore my comment
Comment #29
swentel commentedAnd the fix - added a new constraint based on Symfony's Regex validator.
Comment #31
andypostthis should care about decimal and thousand separators
Comment #32
swentel commentedComment #33
swentel commentedregex fix. Don't think we should account for comma's as the storage won't allow that IIRC - that's more for formatters at output imo.
Comment #34
swentel commentedComment #35
strykaizerPatch applied and works as needed; Could't find any code issues so marking as rtbc.
Comment #36
alexpottAdding a validator is low risk and this fixes a bug so is permitted during beta. Committed 1c3bfd3 and pushed to 8.0.x. Thanks!
Comment #43
poker10 commentedThis bug seems to be no longer present in D7 as it was fixed by #1068016: number field validation fails to block some invalid input causing later SQL fatal error. There is also a test (NumberFieldTestCase::testNumberDecimalField()) checking inputs like "3-3", "-10-10". I think this can be set as Fixed.