From 46d690ff0188836688811dda9af1b99c44750c48 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 3 Feb 2011 16:35:51 -0800 Subject: smarter normalization of value on option, and htmlParser fixes --- src/Angular.js | 2 +- src/markups.js | 33 +++++++++++++++++++-------------- src/sanitizer.js | 35 +++++++++++++++-------------------- test/markupSpec.js | 14 ++++++++++++-- test/sanitizerSpec.js | 15 +++++++++++++-- test/testabilityPatch.js | 4 ++-- test/widgetsSpec.js | 2 +- 7 files changed, 63 insertions(+), 42 deletions(-) diff --git a/src/Angular.js b/src/Angular.js index de2de30d..aea1dd3f 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -719,7 +719,7 @@ function elementError(element, type, error) { element[0]['$NG_ERROR'] = error; if (error) { element.addClass(type); - element.attr(type, error); + element.attr(type, error.message || error); } else { element.removeClass(type); element.removeAttr(type); diff --git a/src/markups.js b/src/markups.js index 0aa7170e..89cc0d05 100644 --- a/src/markups.js +++ b/src/markups.js @@ -57,21 +57,26 @@ angularTextMarkup('{{}}', function(text, textNode, parentElement) { } }); -// TODO: this should be widget not a markup -angularTextMarkup('OPTION', function(text, textNode, parentElement){ - if (nodeName_(parentElement) == "OPTION") { - var select = jqLite(''); expect(element).toHaveValue('\n'); }); diff --git a/test/sanitizerSpec.js b/test/sanitizerSpec.js index 7158fbee..787ce84c 100644 --- a/test/sanitizerSpec.js +++ b/test/sanitizerSpec.js @@ -14,6 +14,11 @@ describe('HTML', function(){ attrs: attrs, unary: unary }; + // Since different browsers handle newlines differenttly we trim + // so that it is easier to write tests. + forEach(attrs, function(value, key){ + attrs[key] = trim(value); + }); }, chars: function(text_){ text = text_; @@ -38,16 +43,22 @@ describe('HTML', function(){ it('should parse newlines in attributes', function(){ htmlParser('text', handler); - expect(start).toEqual({tag:'tag', attrs:{attr:'\nvalue\n'}, unary:false}); + expect(start).toEqual({tag:'tag', attrs:{attr:'value'}, unary:false}); expect(text).toEqual('text'); }); it('should parse namespace', function(){ htmlParser('text', handler); - expect(start).toEqual({tag:'ns:t-a-g', attrs:{'ns:a-t-t-r':'\nvalue\n'}, unary:false}); + expect(start).toEqual({tag:'ns:t-a-g', attrs:{'ns:a-t-t-r':'value'}, unary:false}); expect(text).toEqual('text'); }); + it('should parse empty value attribute of node', function(){ + htmlParser('', handler); + expect(start).toEqual({tag:'option', attrs:{selected:'', value:''}, unary:false}); + expect(text).toEqual('abc'); + }); + }); it('should echo html', function(){ diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index 76033ab2..e0086b8a 100644 --- a/test/testabilityPatch.js +++ b/test/testabilityPatch.js @@ -70,7 +70,7 @@ beforeEach(function(){ expected = toJson(this.actual); } return "Expected " + expected + " to be an Error with message " + toJson(message); - } + }; return this.actual.name == 'Error' && this.actual.message == message; }, @@ -83,7 +83,7 @@ beforeEach(function(){ expected = toJson(this.actual); } return "Expected " + expected + " to match an Error with message " + toJson(messageRegexp); - } + }; return this.actual.name == 'Error' && messageRegexp.test(this.actual.message); } }); diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index ee339e89..6bff5a36 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -475,7 +475,7 @@ describe("widget", function(){ scope.$eval(); expect(scope.$element.text()).toBe('foobarC'); - }) + }); }); -- cgit v1.2.3