Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

fix(forms): parse exponential notation in numberInputType parser #12122

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ng/directive/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
var ISO_DATE_REGEXP = /\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z)/;
var URL_REGEXP = /^(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?$/;
var EMAIL_REGEXP = /^[a-z0-9!#$%&'*+\/=?^_`{|}~.-]+@[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*$/i;
var NUMBER_REGEXP = /^\s*(\-|\+)?(\d+|(\d*(\.\d*)))\s*$/;
var NUMBER_REGEXP = /^\s*(\-|\+)?(\d+|(\d*(\.\d*)))([eE][+-]?\d+)?\s*$/;
var DATE_REGEXP = /^(\d{4})-(\d{2})-(\d{2})$/;
var DATETIMELOCAL_REGEXP = /^(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d)(?::(\d\d)(\.\d{1,3})?)?$/;
var WEEK_REGEXP = /^(\d{4})-W(\d\d)$/;
Expand Down
65 changes: 65 additions & 0 deletions test/ng/directive/inputSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1917,6 +1917,71 @@ describe('input', function() {
});


it('should parse exponential notation', function() {
var inputElm = helper.compileInput('<input type="number" name="alias" ng-model="value" />');

// #.###e+##
$rootScope.form.alias.$setViewValue("1.23214124123412412e+26");
expect(inputElm).toBeValid();
expect($rootScope.value).toBe(1.23214124123412412e+26);

// #.###e##
$rootScope.form.alias.$setViewValue("1.23214124123412412e26");
expect(inputElm).toBeValid();
expect($rootScope.value).toBe(1.23214124123412412e26);

// #.###e-##
$rootScope.form.alias.$setViewValue("1.23214124123412412e-26");
expect(inputElm).toBeValid();
expect($rootScope.value).toBe(1.23214124123412412e-26);

// ####e+##
$rootScope.form.alias.$setViewValue("123214124123412412e+26");
expect(inputElm).toBeValid();
expect($rootScope.value).toBe(123214124123412412e26);

// ####e##
$rootScope.form.alias.$setViewValue("123214124123412412e26");
expect(inputElm).toBeValid();
expect($rootScope.value).toBe(123214124123412412e26);

// ####e-##
$rootScope.form.alias.$setViewValue("123214124123412412e-26");
expect(inputElm).toBeValid();
expect($rootScope.value).toBe(123214124123412412e-26);

// #.###E+##
$rootScope.form.alias.$setViewValue("1.23214124123412412E+26");
expect(inputElm).toBeValid();
expect($rootScope.value).toBe(1.23214124123412412e+26);

// #.###E##
$rootScope.form.alias.$setViewValue("1.23214124123412412E26");
expect(inputElm).toBeValid();
expect($rootScope.value).toBe(1.23214124123412412e26);

// #.###E-##
$rootScope.form.alias.$setViewValue("1.23214124123412412E-26");
expect(inputElm).toBeValid();
expect($rootScope.value).toBe(1.23214124123412412e-26);

// ####E+##
$rootScope.form.alias.$setViewValue("123214124123412412E+26");
expect(inputElm).toBeValid();
expect($rootScope.value).toBe(123214124123412412e26);

// ####E##
$rootScope.form.alias.$setViewValue("123214124123412412E26");
expect(inputElm).toBeValid();
expect($rootScope.value).toBe(123214124123412412e26);

// ####E-##
$rootScope.form.alias.$setViewValue("123214124123412412E-26");
expect(inputElm).toBeValid();
expect($rootScope.value).toBe(123214124123412412e-26);
});


describe('min', function() {

it('should validate', function() {
Expand Down