Today I struggeled with replace function

I have sample script that works in browser and replaces class=" with
class=\"

A=function(){};

A.prototype.re1=/"/g;
A.prototype.doRep=function(s){
return s.replace(this.re1,"\\\"");
}

console.log(new A().doRep("class=\""));


I took the same script and ported to java:

  public static void main(String[] args) {
    Context cx = Context.enter();
    ScriptableObject scope = cx.initStandardObjects();

    StringBuilder sb = new StringBuilder();
    sb.append("A=function(){}; \n");
    sb.append("A.prototype.re1=/\"/g; \n");
    sb.append("A.prototype.doRep=function(s){\n");
    sb.append("return s.replace(this.re1,\"\\\"\"); \n");
    sb.append("}; \n");

    sb.append("java.lang.System.out.println(").append("new
A().doRep(\"class=\\\"\")").append(");");

    cx.evaluateString(scope, sb.toString(), "<cms>", 1, null);
    Context.exit();
  }

In java the same script does *not* work. Does anyone know the reason
or can assure that this should not be like that and is a bug?
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino

Reply via email to