18 January 2026:


This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.



Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.

javascript truncated by CharacterFilter if contains bytes 110,120, etc

grigoriogrigorio Members
edited November -1 in Sahi - Open Source
Hi, Narayan, it related to:

http://sahi.co.in/forums/viewtopic.php?id=1551

we found Sahi truncates a javascript coming from our Confluence server, a javascript of size near 450K is truncated to approx. 360K, because exception CharacterCodingException is thrown when fullData.length = 1 and it contains bytes:
110, 120, 115, 90, 110, 13, 32.

we fixed code in CharacterFilter.java:

before:
....................
private CharsetDecoder decoder;

private byte[] leftOver = null;
....................
@Override
public byte[] modify(byte[] data) throws IOException {
byte[] fullData = concatArrays(leftOver, data);
try {
decoder.decode(ByteBuffer.wrap(fullData)).toString();
leftOver = null;
return fullData;
} catch (CharacterCodingException e1) {
leftOver = fullData;
return new byte[0];
}
}

....................
private byte[] concatArrays(byte[] leftOver, byte[] data) {
if (leftOver == null) return data;
byte[] added = new byte[leftOver.length + data.length];
System.arraycopy(leftOver, 0, added, 0, leftOver.length);
System.arraycopy(data, 0, added, leftOver.length, data.length);
return added;
}


after:
@Override
public byte[] modify(byte[] data) throws IOException {
byte[] fullData = data;
try {
decoder.decode(ByteBuffer.wrap(fullData)).toString();
} catch (CharacterCodingException e1) {
int l = fullData.length >= 1 ? fullData [0] : -1;
System.out.println ("gar CharacterCodingException (l = " + l + ") " + e1.getMessage() + " charset = " + decoder.charset().name());
}
return fullData;
}


NOTE Firefox-ajax-freeze problem still remain, despite this fix.

Comments

  • narayannarayan Administrators
    Hey, thanks a lot. We will have a look at why this was so. Could you also specify what character encoding you were using?

    Regards,
    Narayan
  • hi,

    Our Confluence server uses UTF-8 and give it to a browser.

    What about Firefox ajax freeze - I found the solution, I replaced code in file

    concat.js:

    before:
    // ff xhr start
    if (!_sahi.isIE()){
    // var d = new XMLHttpRequest();
    XMLHttpRequest.prototype.openOld = XMLHttpRequest.prototype.open;
    XMLHttpRequest.prototype.open = function(method, url, async, username, password){
    url = ""+url;
    var opened = this.openOld(method, url, async, username, password);
    if (url.indexOf("/_s_/") == -1){
    try{
    if (!_sahi.isComet(url)){
    var xs = _sahi.topSahi().XHRs;
    xs[xs.length] = this;
    }
    }catch(e){
    _sahi._debug("concat.js: Diff domain: Could not add XHR to list for automatic monitoring "+e);
    }
    this.setRequestHeader("sahi-isxhr", "true");
    }
    return opened;
    }
    new_ActiveXObject = function(s){ // Some custom implementation of ActiveXObject
    return new ActiveXObject(s);
    }
    }else{
    new_ActiveXObject = function(s){
    var lower = s.toLowerCase();
    if (lower.indexOf("microsoft.xmlhttp")!=-1 || lower.indexOf("msxml2.xmlhttp")!=-1){
    return new SahiXHRWrapper(s, true);
    }else{
    return new ActiveXObject(s);
    }
    }
    }
    // ff xhr end

    after:
    // ff xhr start
    if (!_sahi.isIE()){
    new_ActiveXObject = function(s){
    var lower = s.toLowerCase();
    if (lower.indexOf("microsoft.xmlhttp")!=-1 || lower.indexOf("msxml2.xmlhttp")!=-1){
    return new SahiXHRWrapper(s, true);
    }else{
    return new ActiveXObject(s);
    }
    }
    }else{
    new_ActiveXObject = function(s){
    var lower = s.toLowerCase();
    if (lower.indexOf("microsoft.xmlhttp")!=-1 || lower.indexOf("msxml2.xmlhttp")!=-1){
    return new SahiXHRWrapper(s, true);
    }else{
    return new ActiveXObject(s);
    }
    }
    }
    // ff xhr end

    it plays ok, without freeze and JS errors in Firefox 3.5 & 3.6.3.

    I dont't know what other side effects this replacement may open.. so I wait for your comment..
Sign In or Register to comment.