Skip to content
Snippets Groups Projects
Commit b1f40ec9 authored by rswindell's avatar rswindell
Browse files

html_encode now encodes ex-ASCII chars by default.

An optional 3rd bool parameter can be used to disable the encoding of white-
space characters (LF, CR, and TAB).
parent 42d5f82b
Branches
Tags
No related merge requests found
......@@ -112,7 +112,7 @@ js_load(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
errno = 0;
if(strcspn(filename,"/\\")==strlen(filename)) {
sprintf(path,"%s%s",cfg->mods_dir,filename);
if(cfg->mods_dir[0]==0 || !fexist(path))
if(cfg->mods_dir[0]==0 || !fexistcase(path))
sprintf(path,"%s%s",cfg->exec_dir,filename);
} else
strcpy(path,filename);
......@@ -706,7 +706,8 @@ js_html_encode(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rva
ulong i,j;
uchar* inbuf;
uchar* outbuf;
JSBool exascii=JS_FALSE;
JSBool exascii=JS_TRUE;
JSBool wsp=JS_TRUE;
JSString* js_str;
if((inbuf=JS_GetStringBytes(JS_ValueToString(cx, argv[0])))==NULL)
......@@ -715,6 +716,9 @@ js_html_encode(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rva
if(argc>1 && JSVAL_IS_BOOLEAN(argv[1]))
exascii=JSVAL_TO_BOOLEAN(argv[1]);
if(argc>2 && JSVAL_IS_BOOLEAN(argv[2]))
wsp=JSVAL_TO_BOOLEAN(argv[2]);
if((outbuf=(char*)malloc((strlen(inbuf)*10)+1))==NULL)
return(JS_FALSE);
......@@ -723,7 +727,10 @@ js_html_encode(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rva
case TAB:
case LF:
case CR:
j+=sprintf(outbuf+j,"&#%u;",inbuf[i]);
if(wsp)
j+=sprintf(outbuf+j,"&#%u;",inbuf[i]);
else
outbuf[j++]=inbuf[i];
break;
case '"':
j+=sprintf(outbuf+j,""");
......@@ -1234,8 +1241,9 @@ static jsMethodSpec js_global_functions[] = {
{"format", js_format, 1, JSTYPE_STRING, JSDOCSTR("string format [,args]")
,JSDOCSTR("return a formatted string (ala sprintf)")
},
{"html_encode", js_html_encode, 1, JSTYPE_STRING, JSDOCSTR("string text [,bool ex_ascii]")
,JSDOCSTR("return an HTML-encoded text buffer (using standard HTML character entities), optionally escaping IBM extended-ASCII characters")
{"html_encode", js_html_encode, 1, JSTYPE_STRING, JSDOCSTR("string text [,bool ex_ascii] [,bool white_space]")
,JSDOCSTR("return an HTML-encoded text buffer (using standard HTML character entities), "
"escaping IBM extended-ASCII and white-space characters by default")
},
{"html_decode", js_html_decode, 1, JSTYPE_STRING, JSDOCSTR("string text")
,JSDOCSTR("return a decoded HTML-encoded text buffer")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment