Hi, Firstly let me say that the URITemplate impl is great and works great for us. Recently I came across an issue with the -neg operator which seems to deviates from the spec. The spec states the following:
http://bitworking.org/projects/URI-Templates/spec/draft-gregorio-uritemplate-02.txt 3.3.2. The 'neg' operator If all of the variables are un-defined or empty then substitute the value of arg, otherwise substitute the empty string. Template t = new Template("http://cnn.com/{-neg|all|foo,bar}";); Map m = new HashMap(); m.put("foo", "value"); String out = t.expand(m); out => http://cnn.com/all Note that the output returns "all" inspite of one of the variables being declared. If I read correctly, it should return "http://cnn.com" instead of "http://cnn.com/all" Can you please confirm that this is a bug or point me to the correct spec? After debugging this a bit, it looks like this can be fixed with the following diff (I'm looking at the sources from abdera-i18n-1.0-20090105.215721-1-sources.jar) --- ./org/apache/abdera/i18n/templates/Operation.java 2008-12-19 12:54:26.000000000 -0800 +++ ./patch/Operation.java 2009-03-25 17:39:18.000000000 -0700 @@ -528,9 +528,9 @@ public String evaluate(String var, String arg, Context context) { String[] vardefs = var.split("\\s*,\\s*"); for (String v : vardefs) { - if (!isdefined(v,context)) return arg; + if (isdefined(v,context)) return null; } - return null; + return arg; } public void explain(String var, String arg, Appendable buf) throws IOException { buf.append("If ["); Let me know if you'd like me to file a bug. thanks, Nagesh
