2010-07-23 3 views
1
내가 같이 Rhino에서 XHTML을 생성하지만 내 URL을 인코딩되고 사용하고

에서 E4X와 생성 된 URL :코뿔소, XHTML

- 실패 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(); 
     } 

    } 
} 

아이디어가 없습니다. ?

+0

btw, 나는 .replace ("&", "&")로 갈 것입니다. 그러나이 유스 케이스에 대한 조항이 다른 방법으로 있는지 알아두면 좋을 것입니다. –

답변

0

사실 & 이름부터 xHTML에서 인코딩 "& amp;"가 올바른 것입니다. 유효한 xHTML 엔터티가 아닙니다. 모든 브라우저는 URL을 올바르게 인식합니다. 따라서 올바른 xHTML을 깨뜨리기보다는 테스트를 수정해야합니다. :-) stw