[Pkg-javascript-commits] [dojo] 12/32: Fix issues with widgets being instantiated with {dir: undefined, lang: undefined} parameters, or worse yet {dir: "undefined", lang: "undefined"}. Don't pass in dir, lang as parameters unless they have valid (non-null, non-empty-string) values.

David Prévot taffit at moszumanska.debian.org
Thu Aug 21 17:39:07 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to annotated tag 1.6.2
in repository dojo.

commit a4ad8dfa83506ea0ade1f5edff925c1388f3d264
Author: Bill Keese <bill at dojotoolkit.org>
Date:   Tue Apr 12 05:45:25 2011 +0000

    Fix issues with widgets being instantiated with {dir: undefined, lang: undefined} parameters, or worse yet {dir: "undefined", lang: "undefined"}.     Don't pass in dir, lang as parameters unless they have valid (non-null, non-empty-string) values.
    
    Fixes #12614 on 1.6/ branch (trunk checkin will follow), !strict.
    
    git-svn-id: http://svn.dojotoolkit.org/src/branches/1.6/dojo@24277 560b804f-0ae3-0310-86f3-f6aa0a117693
---
 html.js                  |  11 +-
 parser.js                |  15 ++-
 tests/html/test_set.html |  60 ++++++++++
 tests/parser.html        | 278 +++++++++++++++++++++++++++--------------------
 4 files changed, 236 insertions(+), 128 deletions(-)

diff --git a/html.js b/html.js
index 98cbf55..03519d0 100644
--- a/html.js
+++ b/html.js
@@ -264,13 +264,16 @@ dojo.getObject("html", true, dojo);
 				var rootNode = this.node;
 				try{
 					// store the results (widgets, whatever) for potential retrieval
+					var inherited = {};
+					dojo.forEach(["dir", "lang", "textDir"], function(name){
+						if(this[name]){
+							inherited[name] = this[name];
+						}
+					}, this);
 					this.parseResults = dojo.parser.parse({
 						rootNode: rootNode,
 						noStart: !this.startup,
-						inherited: {
-							dir: this.dir,
-							lang: this.lang
-						},
+						inherited: inherited,
 						scope: this.parserScope
 					});
 				}catch(e){
diff --git a/parser.js b/parser.js
index 57027af..b151c2a 100644
--- a/parser.js
+++ b/parser.js
@@ -423,6 +423,7 @@ dojo.parser = new function(){
 		}else{
 			root = rootNode;
 		}
+		root = root ? dojo.byId(root) : dojo.body();
 		args = args || {};
 
 		var attrName = (args.scope || d._scopeName) + "Type",		// typically "dojoType"
@@ -508,13 +509,19 @@ dojo.parser = new function(){
 			}
 		}
 
+		// Ignore bogus entries in inherited hash like {dir: ""}
+		var inherited = {};
+		if(args && args.inherited){
+			for(var key in args.inherited){
+				if(args.inherited[key]){ inherited[key] = args.inherited[key]; }
+			}
+		}
+
 		// Make list of all nodes on page w/dojoType specified
 		var list = [];
 		scan({
-			node: root ? dojo.byId(root) : dojo.body(),
-			inherited: (args && args.inherited) || {
-				dir: dojo._isBodyLtr() ? "ltr" : "rtl"
-			}
+			node: root,
+			inherited: inherited
 		}, list);
 
 		// go build the object instances
diff --git a/tests/html/test_set.html b/tests/html/test_set.html
index e3bde7b..aeb48f9 100644
--- a/tests/html/test_set.html
+++ b/tests/html/test_set.html
@@ -415,6 +415,66 @@
 				}
 			]);
 
+			// Test specification of inherited attributes dir, lang, etc.
+			var handle;
+			doh.register("inherited", [
+				{
+					name: 'unspecified',
+					runTest: function(t){
+						var cont = '<div dojoType="dojo.html.test.SimpleThing" jsId="ifrs" data="{}"></div>';
+
+						var parserCalled, inherited;
+						handle = dojo.connect(dojo.parser, "parse", function(args){
+							parserCalled = true;
+							inherited = args.inherited;
+						});
+
+						dojo.html.set(
+							dojo.byId("pane1"),
+							cont,
+							{
+								parseContent: true
+							}
+						);
+						doh.t(parserCalled, "parser was called");
+						doh.f("dir" in inherited, "no dir specified");
+						doh.f("lang" in inherited, "no lang specified");
+					},
+					tearDown: function(){
+						dojo.disconnect(handle);
+					}
+				},
+				{
+					name: 'specified',
+					runTest: function(t){
+						var cont = '<div dojoType="dojo.html.test.SimpleThing" jsId="ifrs" data="{}"></div>';
+
+						var parserCalled, inherited;
+						handle = dojo.connect(dojo.parser, "parse", function(args){
+							parserCalled = true;
+							inherited = args.inherited;
+						});
+
+						dojo.html.set(
+							dojo.byId("pane1"),
+							cont,
+							{
+								dir: "rtl",
+								lang: "it_it",
+								parseContent: true
+							}
+						);
+						doh.t(parserCalled, "parser was called");
+						doh.is("rtl", inherited.dir, "dir");
+						doh.is("it_it", inherited.lang, "lang");
+					},
+					tearDown: function(){
+						dojo.disconnect(handle);
+					}
+				}
+
+			]);
+
 			doh.run();
 		}); 
 	</script>
diff --git a/tests/parser.html b/tests/parser.html
index a491535..7b19b20 100644
--- a/tests/parser.html
+++ b/tests/parser.html
@@ -11,6 +11,12 @@
 		<script type="text/javascript">
 		define("dojo/tests/parser/script", ["dojo", "dojo/parser", "doh/runner"], function(dojo) {
 
+			dojo.declare("tests.parser.Widget", null, {
+				constructor: function(args, node){
+					this.params = args;
+				}
+			});
+
 			dojo.declare("tests.parser.Class1", null, {
 				constructor: function(args, node){
 					this.params = args;
@@ -73,10 +79,11 @@
 				checked: false
 			});
 
-			// Test that dir attribute can be inherited from ancestor node
-			dojo.declare("tests.parser.DirClass", null, {
+			// Test that dir, lang, etc. attribute can be inherited from ancestor node
+			dojo.declare("tests.parser.BidiClass", tests.parser.Widget, {
 				constructor: function(args, node){ dojo.mixin(this, args); },
 				dir: "",
+				lang: "",
 				name: ""
 			});
 
@@ -126,11 +133,11 @@
 			};
 
 			dojo.addOnLoad(function(){
-				doh.register("t",
+				doh.register("basic",
 					[
 						function parse(){
 							// Running the parser here so that failures appear in test log
-							dojo.parser.parse();
+							dojo.parser.parse("main");
 						},
 
 						function testJsId(t){
@@ -321,15 +328,6 @@
 							doh.is(12345, widgets[0].params.newParam, "new parameter parsed");
 						},
 
-						// Test that dir=rtl or dir=ltr setting trickles down from root node
-						function dir(){				
-							doh.is("rtl", setRtl.dir, "direct setting of dir=rtl works");
-							doh.is("rtl", inheritRtl.dir, "inherited rtl works");
-							doh.is("ltr", inheritLtr.dir, "inherited ltr works (closest ancestor wins)");
-							doh.is("rtl", inheritRtl2.dir, "inherited rtl works, from grandparent");
-							doh.is("ltr", setLtr.dir, "direct setting of dir=ltr overrides inherited RTL");
-						},
-						
 						// Test that parser recurses correctly, except when there's a stopParser flag not to
 						function recurse(){
 							doh.t(container1, "normal container created");
@@ -383,6 +381,26 @@
 						}
 					]
 				);
+
+				doh.register("BIDI", [
+					// Test that dir=rtl or dir=ltr setting trickles down from root node
+					function dir(){
+						dojo.parser.parse("dirSection1");
+						dojo.parser.parse("dirSection2");
+						doh.is("rtl", setRtl.dir, "direct setting of dir=rtl works");
+						doh.is("rtl", inheritRtl.dir, "inherited rtl works");
+						doh.is("ltr", inheritLtr.dir, "inherited ltr works (closest ancestor wins)");
+						doh.is("rtl", inheritRtl2.dir, "inherited rtl works, from grandparent");
+						doh.is("ltr", setLtr.dir, "direct setting of dir=ltr overrides inherited RTL");
+					},
+					function lang(){
+						dojo.parser.parse("langSection");
+						doh.f(lang in noLang.params, "no lang");
+						doh.is("it_it", inheritedLang.lang, "inherited lang works");
+						doh.is("en_us", specifiedLang.lang,"direct setting of lang overrides inherited");
+					}
+				]);
+
 				doh.run();
 			})
 		});
@@ -390,126 +408,146 @@
 	</head>
 	<body>
 		<h1>Parser Unit Test</h1>
-		<script>
-			function foo(){ this.fooCalled=true; }
-		</script>
-		<div dojoType="tests.parser.Class1" data-dojo-id="obj" 
-			strProp1="text" strProp2=""
-			intProp="5"
-			arrProp="foo, bar, baz"
-			arrProp2=""
-			boolProp1="true" boolProp2="false"
-			dateProp1="2006-01-01" dateProp2="" dateProp3="now"
-			funcProp2="foo" funcProp3="this.func3Called=true;"
-		>
-			<script type="dojo/method" event="preamble">
-				this.preambleTestProp = 3;
-			</script>
-			<script type="dojo/method">
-				// this should be run immediately
-				this.deepProp = deepTestProp;
-			</script>
-			<script type="dojo/connect" event="callInc">
-				this.callCount++;
-			</script>
-			<script type="dojo/method" event="callInc2">
-				this.callCount2++;
+
+		<div id="main">
+			<script>
+				function foo(){ this.fooCalled=true; }
 			</script>
-		</div>
-		<div>
-			<div type="tests.parser.Class1" jsId="obj2" id="toParse">
+			<div dojoType="tests.parser.Class1" data-dojo-id="obj"
+				strProp1="text" strProp2=""
+				intProp="5"
+				arrProp="foo, bar, baz"
+				arrProp2=""
+				boolProp1="true" boolProp2="false"
+				dateProp1="2006-01-01" dateProp2="" dateProp3="now"
+				funcProp2="foo" funcProp3="this.func3Called=true;"
+			>
+				<script type="dojo/method" event="preamble">
+					this.preambleTestProp = 3;
+				</script>
+				<script type="dojo/method">
+					// this should be run immediately
+					this.deepProp = deepTestProp;
+				</script>
+				<script type="dojo/connect" event="callInc">
+					this.callCount++;
+				</script>
+				<script type="dojo/method" event="callInc2">
+					this.callCount2++;
+				</script>
 			</div>
-		</div>
-		<div dojoType="tests.parser.Class2" jsId="obj3">
-		</div>
-		<div dojoType="tests.parser.Class3" jsId="obj4">
-		</div>
-		<input dojoType="tests.parser.inputClass" jsId="checkedObj" checked type="checkbox">
-		<button dojoType="tests.parser.inputClass" jsId="disabledObj" disabled>hi</button>
-		
-		<div id="parsertest"></div>
-		<div id="parsertest2"></div>
-
-		<!-- section for testing that dir attribute trickles down from ancestor -->
-		<div dojoType="tests.parser.DirClass" jsId="setRtl" dir="rtl" name="RTL setting"></div>
-		<div dir="rtl">
-			<div dojoType="tests.parser.DirClass" jsId="inheritRtl" name="inherited RTL from parent"></div>
-			<div dir="ltr">
-				<div dojoType="tests.parser.DirClass" jsId="inheritLtr" name="inherited LTR from parent"></div>
+			<div>
+				<div type="tests.parser.Class1" jsId="obj2" id="toParse">
+				</div>
+			</div>
+			<div dojoType="tests.parser.Class2" jsId="obj3">
+			</div>
+			<div dojoType="tests.parser.Class3" jsId="obj4">
 			</div>
+			<input dojoType="tests.parser.inputClass" jsId="checkedObj" checked type="checkbox">
+			<button dojoType="tests.parser.inputClass" jsId="disabledObj" disabled>hi</button>
+
+			<div id="parsertest"></div>
+			<div id="parsertest2"></div>
+
+			<!-- section for testing parser recursion -->
 			<div>
-				<div dojoType="tests.parser.DirClass" jsId="inheritRtl2" name="inherited RTL from grandparent"></div>
+				<div dojoType="tests.parser.NormalContainer" jsId="container1">
+					<!-- this script tag should get passed as param to NormalContainer constructor -->
+					<script type="dojo/method" event="incr" args="x">
+						return x+1;
+					</script>
+
+					<!-- and these contained widgets should get instantiated -->
+					<div dojoType="tests.parser.Class1" jsId="contained1"></div>
+					<div>
+						<div dojoType="tests.parser.Class1" jsId="contained2"></div>
+					</div>
+				</div>
 			</div>
-			<div dojoType="tests.parser.DirClass" jsId="setLtr" dir="ltr" name="LTR setting overrides inherited RTL"></div>
-		</div>
-		<div dojoType="tests.parser.DirClass" jsId="noDir" name="dir not inherited or set"></div>
-		
-		<!-- section for testing parser recursion -->
-
-		<div>
-			<div dojoType="tests.parser.NormalContainer" jsId="container1">
-				<!-- this script tag should get passed as param to NormalContainer constructor -->
-				<script type="dojo/method" event="incr" args="x">
-					return x+1;
-				</script>
-				
-				<!-- and these contained widgets should get instantiated -->
-				<div dojoType="tests.parser.Class1" jsId="contained1"></div>
-				<div>
-					<div dojoType="tests.parser.Class1" jsId="contained2"></div>			
+
+			<div>
+				<div dojoType="tests.parser.ShieldedContainer" jsId="container2">
+					<!-- this script tag should get passed as param to NormalContainer constructor -->
+					<script type="dojo/method" event="incr" args="x">
+						return x+1;
+					</script>
+
+					<!-- but these contained widgets should *not* get instantiated -->
+					<div dojoType="tests.parser.Class1" jsId="contained3"></div>
+					<div>
+						<div dojoType="tests.parser.Class1" jsId="contained4"></div>
+					</div>
 				</div>
 			</div>
-		</div>
 
-		<div>
-			<div dojoType="tests.parser.ShieldedContainer" jsId="container2">
-				<!-- this script tag should get passed as param to NormalContainer constructor -->
-				<script type="dojo/method" event="incr" args="x">
-					return x+1;
-				</script>
-				
-				<!-- but these contained widgets should *not* get instantiated -->
-				<div dojoType="tests.parser.Class1" jsId="contained3"></div>
-				<div>
-					<div dojoType="tests.parser.Class1" jsId="contained4"></div>			
+			<div>
+				<div data-dojo-id="html5simple" data-dojo-type="tests.parser.HTML5Props" data-dojo-props="simple:true"></div>
+				<div data-dojo-id="html5simple2" data-dojo-type="tests.parser.HTML5Props"
+					data-dojo-props="simple:false, a:1, b:'two', c:[1,2,3], d:function(){ return this; }, e:{ f:'g' }"
+				></div>
+				<!-- note needing to use a named inherited lookup because we're just mixing in -->
+				<div data-dojo-id="html5simple3" data-dojo-type="tests.parser.HTML5Props"
+					data-dojo-props="afn: function(){ return this.inherited('afn', arguments); }"
+				></div>
+
+				<!-- not used for tests, but thinking out loud: what about a named-resource prop, via getObject -->
+				<div data-dojo-id="html5fromobjectns" data-dojo-type="tests.parser.HTML5Props"
+					data-dojo-obj="tests.parser.HTML5Props._aDefaultObj"
+				></div>
+				<div data-dojo-id="html5fromobjectns2" data-dojo-type="tests.parser.HTML5Props"
+					data-dojo-obj="tests.parser.HTML5Props._aDefaultObj" data-dojo-props="simple:false"
+				></div>
+
+			</div>
+
+			<div>
+				<div data-dojo-id="htmldojomethod" data-dojo-type="tests.parser.HTML5withMethod">
+					<p>Some random markup</p>
+					<script type="dojo/method" data-dojo-event="someMethod" data-dojo-args="a, b">
+						return this.baseValue + a + b;
+					</script>
+					<script type="dojo/connect" data-dojo-event="diffMethod" data-dojo-args="a">
+						this._fromvalue = a;
+					</script>
+					<script type="dojo/method">
+						this._methodRan = true;
+					</script>
 				</div>
 			</div>
-		</div>
+		</div> <!-- close <div id=main> -->
 
-		<div>
-			<div data-dojo-id="html5simple" data-dojo-type="tests.parser.HTML5Props" data-dojo-props="simple:true"></div>
-			<div data-dojo-id="html5simple2" data-dojo-type="tests.parser.HTML5Props"
-				data-dojo-props="simple:false, a:1, b:'two', c:[1,2,3], d:function(){ return this; }, e:{ f:'g' }"
-			></div>
-			<!-- note needing to use a named inherited lookup because we're just mixing in -->
-			<div data-dojo-id="html5simple3" data-dojo-type="tests.parser.HTML5Props"
-				data-dojo-props="afn: function(){ return this.inherited('afn', arguments); }"
-			></div>
-			
-			<!-- not used for tests, but thinking out loud: what about a named-resource prop, via getObject -->
-			<div data-dojo-id="html5fromobjectns" data-dojo-type="tests.parser.HTML5Props"
-				data-dojo-obj="tests.parser.HTML5Props._aDefaultObj"
-			></div>
-			<div data-dojo-id="html5fromobjectns2" data-dojo-type="tests.parser.HTML5Props"
-				data-dojo-obj="tests.parser.HTML5Props._aDefaultObj" data-dojo-props="simple:false"
-			></div>
-			
+		<!-- section for testing that dir, lang attribute trickles down from ancestor -->
+		<div id="dirSection1">
+			<div dojoType="tests.parser.BidiClass" jsId="setRtl" dir="rtl" name="RTL setting"></div>
+			<div dojoType="tests.parser.BidiClass" jsId="noDir" name="dir not inherited or set"></div>
 		</div>
-		
-		<div>
-			<div data-dojo-id="htmldojomethod" data-dojo-type="tests.parser.HTML5withMethod">
-				<p>Some random markup</p>
-				<script type="dojo/method" data-dojo-event="someMethod" data-dojo-args="a, b">
-					return this.baseValue + a + b;
-				</script>
-				<script type="dojo/connect" data-dojo-event="diffMethod" data-dojo-args="a">
-					this._fromvalue = a;
-				</script>
-				<script type="dojo/method">
-					this._methodRan = true;
-				</script>
+		<div id="dirSection2" dir="rtl">
+			<div dojoType="tests.parser.BidiClass" jsId="inheritRtl" name="inherited RTL from parent"></div>
+			<div dir="ltr">
+				<div dojoType="tests.parser.BidiClass" jsId="inheritLtr" name="inherited LTR from parent"></div>
 			</div>
+			<div>
+				<div dojoType="tests.parser.BidiClass" jsId="inheritRtl2" name="inherited RTL from grandparent"></div>
+			</div>
+			<div dojoType="tests.parser.BidiClass" jsId="setLtr" dir="ltr" name="LTR setting overrides inherited RTL"></div>
+		</div>
+		<div id="langSection">
+			<div dojoType="tests.parser.BidiClass" jsId="noLang" name="shouldn't get lang"></div>
+			<div lang="it_it">
+				<div dojoType="tests.parser.BidiClass" jsId="inheritedLang" name="inherited lang from parent"></div>
+				<div dojoType="tests.parser.BidiClass" jsId="specifiedLang" lang="en_us" name="specified lang overrides parent"></div>
+			</div>
+		</div>
+		<div id="textDirSection">
+			<div dojoType="tests.parser.BidiClass" jsId="noTextdir" name="shouldn't get textdir"></div>
+			<div data-dojo-textdir="rtl">
+				<div dojoType="tests.parser.BidiClass" jsId="inheritedTextdir" name="inherited textdir from parent"></div>
+				<div dojoType="tests.parser.BidiClass" jsId="specifiedTextdir" data-dojo-textdir="ltr" name="specified textdir overrides parent"></div>
+			</div>
+		</div>
+		<div id="bidiInheritanceFromHtml">
+			<div dojoType="tests.parser.BidiClass" jsId="inheritedFromHtml" name="should get dir/lang/textDir from HTML tag"></div>
 		</div>
-
 	</body>
 </html>

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/dojo.git



More information about the Pkg-javascript-commits mailing list