1

我正在使用 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();
        }

    }
}

有任何想法吗?

4

1 回答 1

0

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

于 2011-04-06T12:48:49.377 回答