Browse Source

added DETooManyValues

Nicolas Cannasse 13 years ago
parent
commit
d31a8e77bb
2 changed files with 8 additions and 0 deletions
  1. 1 0
      doc/CHANGES.txt
  2. 7 0
      std/haxe/web/Dispatch.hx

+ 1 - 0
doc/CHANGES.txt

@@ -8,6 +8,7 @@
 	all : new post-compilation DCE
 	all : Std.random(x) when x <= 0 is now always 0
 	spod : added serialized data with SData<T>
+	all : Dispatcher will now throw DETooManyValues
 
 2012-07-16: 2.10
 	java/cs : added two new targets (beta)

+ 7 - 0
std/haxe/web/Dispatch.hx

@@ -59,6 +59,7 @@ enum DispatchError {
 	DEInvalidValue;
 	DEMissing;
 	DEMissingParam( p : String );
+	DETooManyValues;
 }
 
 private class Redirect {
@@ -72,6 +73,7 @@ class Dispatch {
 	public var params : Hash<String>;
 	public var name : String;
 	public var cfg : DispatchConfig;
+	var subDispatch : Bool;
 
 	public function new(url:String, params) {
 		parts = url.split("/");
@@ -122,7 +124,11 @@ class Dispatch {
 		}
 		name = "do" + name.charAt(0).toUpperCase() + name.substr(1);
 		var args = [];
+		subDispatch = false;
 		loop(args, r);
+		if( parts.length > 0 && !subDispatch ) {
+			if( parts.length == 1 && parts[parts.length - 1] == "" ) parts.pop() else throw DETooManyValues;
+		}
 		try {
 			Reflect.callMethod(cfg.obj, Reflect.field(cfg.obj, name), args);
 		} catch( e : Redirect ) {
@@ -166,6 +172,7 @@ class Dispatch {
 		case MRDispatch:
 			if( v != null )
 				parts.unshift(v);
+			subDispatch = true;
 			return this;
 		case MRSpod(c, lock):
 			if( v == null ) throw DEMissing;