Skip to content

Commit c6c5894

Browse files
Merge pull request #31 from angular/master
Update upstream
2 parents 23c92d9 + aa3f951 commit c6c5894

File tree

5 files changed

+127
-6
lines changed

5 files changed

+127
-6
lines changed

src/ng/compile.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -3647,7 +3647,9 @@ var SPECIAL_CHARS_REGEXP = /[:\-_]+(.)/g;
36473647
function directiveNormalize(name) {
36483648
return name
36493649
.replace(PREFIX_REGEXP, '')
3650-
.replace(SPECIAL_CHARS_REGEXP, fnCamelCaseReplace);
3650+
.replace(SPECIAL_CHARS_REGEXP, function(_, letter, offset) {
3651+
return offset ? letter.toUpperCase() : letter;
3652+
});
36513653
}
36523654

36533655
/**

src/ng/directive/input.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1604,8 +1604,8 @@ function numberInputType(scope, element, attr, ctrl, $sniffer, $browser) {
16041604
var maxVal;
16051605

16061606
if (isDefined(attr.min) || attr.ngMin) {
1607-
ctrl.$validators.min = function(value) {
1608-
return ctrl.$isEmpty(value) || isUndefined(minVal) || value >= minVal;
1607+
ctrl.$validators.min = function(modelValue, viewValue) {
1608+
return ctrl.$isEmpty(viewValue) || isUndefined(minVal) || viewValue >= minVal;
16091609
};
16101610

16111611
attr.$observe('min', function(val) {
@@ -1616,8 +1616,8 @@ function numberInputType(scope, element, attr, ctrl, $sniffer, $browser) {
16161616
}
16171617

16181618
if (isDefined(attr.max) || attr.ngMax) {
1619-
ctrl.$validators.max = function(value) {
1620-
return ctrl.$isEmpty(value) || isUndefined(maxVal) || value <= maxVal;
1619+
ctrl.$validators.max = function(modelValue, viewValue) {
1620+
return ctrl.$isEmpty(viewValue) || isUndefined(maxVal) || viewValue <= maxVal;
16211621
};
16221622

16231623
attr.$observe('max', function(val) {

src/ngSanitize/filter/linky.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Requires the {@link ngSanitize `ngSanitize`} module to be installed.
1313
*
1414
* @param {string} text Input text.
15-
* @param {string} target Window (`_blank|_self|_parent|_top`) or named frame to open links in.
15+
* @param {string} [target] Window (`_blank|_self|_parent|_top`) or named frame to open links in.
1616
* @param {object|function(url)} [attributes] Add custom attributes to the link element.
1717
*
1818
* Can be one of:

test/ng/compileSpec.js

+21
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,27 @@ describe('$compile', function() {
294294
inject(function($compile) {});
295295
});
296296

297+
it('should ignore special chars before processing attribute directive name', function() {
298+
// a regression https://github.com/angular/angular.js/issues/16278
299+
module(function() {
300+
directive('t', function(log) {
301+
return {
302+
restrict: 'A',
303+
link: {
304+
pre: log.fn('pre'),
305+
post: log.fn('post')
306+
}
307+
};
308+
});
309+
});
310+
inject(function($compile, $rootScope, log) {
311+
$compile('<div _t></div>')($rootScope);
312+
$compile('<div -t></div>')($rootScope);
313+
$compile('<div :t></div>')($rootScope);
314+
expect(log).toEqual('pre; post; pre; post; pre; post');
315+
});
316+
});
317+
297318
it('should throw an exception if the directive factory is not defined', function() {
298319
module(function() {
299320
expect(function() {

test/ng/directive/inputSpec.js

+98
Original file line numberDiff line numberDiff line change
@@ -2284,6 +2284,15 @@ describe('input', function() {
22842284

22852285
describe('number', function() {
22862286

2287+
// Helpers for min / max tests
2288+
var subtract = function(value) {
2289+
return value - 5;
2290+
};
2291+
2292+
var add = function(value) {
2293+
return value + 5;
2294+
};
2295+
22872296
it('should reset the model if view is invalid', function() {
22882297
var inputElm = helper.compileInput('<input type="number" ng-model="age"/>');
22892298

@@ -2465,6 +2474,29 @@ describe('input', function() {
24652474
expect($rootScope.form.alias.$error.min).toBeFalsy();
24662475
});
24672476

2477+
2478+
it('should validate against the viewValue', function() {
2479+
var inputElm = helper.compileInput(
2480+
'<input type="number" ng-model-options="{allowInvalid: true}" ng-model="value" name="alias" min="10" />');
2481+
2482+
var ngModelCtrl = inputElm.controller('ngModel');
2483+
ngModelCtrl.$parsers.push(subtract);
2484+
2485+
helper.changeInputValueTo('10');
2486+
expect(inputElm).toBeValid();
2487+
expect($rootScope.value).toBe(5);
2488+
expect($rootScope.form.alias.$error.min).toBeFalsy();
2489+
2490+
ngModelCtrl.$parsers.pop();
2491+
ngModelCtrl.$parsers.push(add);
2492+
2493+
helper.changeInputValueTo('5');
2494+
expect(inputElm).toBeInvalid();
2495+
expect($rootScope.form.alias.$error.min).toBeTruthy();
2496+
expect($rootScope.value).toBe(10);
2497+
});
2498+
2499+
24682500
it('should validate even if min value changes on-the-fly', function() {
24692501
$rootScope.min = undefined;
24702502
var inputElm = helper.compileInput('<input type="number" ng-model="value" name="alias" min="{{min}}" />');
@@ -2511,6 +2543,28 @@ describe('input', function() {
25112543
expect($rootScope.form.alias.$error.min).toBeFalsy();
25122544
});
25132545

2546+
2547+
it('should validate against the viewValue', function() {
2548+
var inputElm = helper.compileInput(
2549+
'<input type="number" ng-model-options="{allowInvalid: true}" ng-model="value" name="alias" ng-min="10" />');
2550+
var ngModelCtrl = inputElm.controller('ngModel');
2551+
ngModelCtrl.$parsers.push(subtract);
2552+
2553+
helper.changeInputValueTo('10');
2554+
expect(inputElm).toBeValid();
2555+
expect($rootScope.value).toBe(5);
2556+
expect($rootScope.form.alias.$error.min).toBeFalsy();
2557+
2558+
ngModelCtrl.$parsers.pop();
2559+
ngModelCtrl.$parsers.push(add);
2560+
2561+
helper.changeInputValueTo('5');
2562+
expect(inputElm).toBeInvalid();
2563+
expect($rootScope.form.alias.$error.min).toBeTruthy();
2564+
expect($rootScope.value).toBe(10);
2565+
});
2566+
2567+
25142568
it('should validate even if the ngMin value changes on-the-fly', function() {
25152569
$rootScope.min = undefined;
25162570
var inputElm = helper.compileInput('<input type="number" ng-model="value" name="alias" ng-min="min" />');
@@ -2558,6 +2612,28 @@ describe('input', function() {
25582612
expect($rootScope.form.alias.$error.max).toBeFalsy();
25592613
});
25602614

2615+
2616+
it('should validate against the viewValue', function() {
2617+
var inputElm = helper.compileInput('<input type="number"' +
2618+
'ng-model-options="{allowInvalid: true}" ng-model="value" name="alias" max="10" />');
2619+
var ngModelCtrl = inputElm.controller('ngModel');
2620+
ngModelCtrl.$parsers.push(add);
2621+
2622+
helper.changeInputValueTo('10');
2623+
expect(inputElm).toBeValid();
2624+
expect($rootScope.value).toBe(15);
2625+
expect($rootScope.form.alias.$error.max).toBeFalsy();
2626+
2627+
ngModelCtrl.$parsers.pop();
2628+
ngModelCtrl.$parsers.push(subtract);
2629+
2630+
helper.changeInputValueTo('15');
2631+
expect(inputElm).toBeInvalid();
2632+
expect($rootScope.form.alias.$error.max).toBeTruthy();
2633+
expect($rootScope.value).toBe(10);
2634+
});
2635+
2636+
25612637
it('should validate even if max value changes on-the-fly', function() {
25622638
$rootScope.max = undefined;
25632639
var inputElm = helper.compileInput('<input type="number" ng-model="value" name="alias" max="{{max}}" />');
@@ -2604,6 +2680,28 @@ describe('input', function() {
26042680
expect($rootScope.form.alias.$error.max).toBeFalsy();
26052681
});
26062682

2683+
2684+
it('should validate against the viewValue', function() {
2685+
var inputElm = helper.compileInput('<input type="number"' +
2686+
'ng-model-options="{allowInvalid: true}" ng-model="value" name="alias" ng-max="10" />');
2687+
var ngModelCtrl = inputElm.controller('ngModel');
2688+
ngModelCtrl.$parsers.push(add);
2689+
2690+
helper.changeInputValueTo('10');
2691+
expect(inputElm).toBeValid();
2692+
expect($rootScope.value).toBe(15);
2693+
expect($rootScope.form.alias.$error.max).toBeFalsy();
2694+
2695+
ngModelCtrl.$parsers.pop();
2696+
ngModelCtrl.$parsers.push(subtract);
2697+
2698+
helper.changeInputValueTo('15');
2699+
expect(inputElm).toBeInvalid();
2700+
expect($rootScope.form.alias.$error.max).toBeTruthy();
2701+
expect($rootScope.value).toBe(10);
2702+
});
2703+
2704+
26072705
it('should validate even if the ngMax value changes on-the-fly', function() {
26082706
$rootScope.max = undefined;
26092707
var inputElm = helper.compileInput('<input type="number" ng-model="value" name="alias" ng-max="max" />');

0 commit comments

Comments
 (0)