代码之家  ›  专栏  ›  技术社区  ›  Jamie McCrindle

Rhino、E4x和在XHTML中生成URL

  •  1
  • Jamie McCrindle  · 技术社区  · 15 年前

    我正在使用Rhino生成XHTML,但我的URL编码为:

    - http://www.example.com/test.html?a=b&c=d

    变成

    - http://www.example.com/test.html?a=b&c=d

    失败测试用例如下:

    public class E4XUrlTest extends TestCase {
        public void testJavascript() throws Exception {
            final Context context = new ContextFactory().enterContext();
            context.setLanguageVersion(Context.VERSION_1_7);
            try {
                final ScriptableObject scope = new Global(context);
                final Script compiledScript  = context.compileReader(
                        new StringReader("<html><body><a href={'blah.html?id=2345&name=345'}></a></body></html>"), "test", 1, null);
                HashMap<String, Object> variables = new HashMap<String, Object>();
                Set<Entry<String, Object>> entrySet = variables.entrySet();
                for (Entry<String, Object> entry : entrySet) {
                    ScriptableObject.putProperty(scope, entry.getKey(), Context.javaToJS(entry.getValue(), scope));
                }
                Object exec = compiledScript.exec(context, scope);
                String html = exec.toString();
                System.out.println(html);
                assertTrue(html.indexOf("id=2345&name") > 0);
            } finally {
                Context.exit();
            }
    
        }
    }
    

    有什么想法吗?

    1 回复  |  直到 15 年前
        1
  •  0
  •   stwissel    15 年前

    实际上,XHTML中的编码“&name”是正确的,因为&name;不是有效的XHTML实体。所有浏览器都正确理解URL。因此,您需要修复测试,而不是破坏正确的XHTML。 -)

    推荐文章