Comparing version
@@ -37,6 +37,5 @@ /* ansi_up.js | ||
function AnsiUp() { | ||
this.VERSION = "4.0.4"; | ||
this.VERSION = "5.0.0"; | ||
this.setup_palettes(); | ||
this._use_classes = false; | ||
this._escape_for_html = true; | ||
this.bold = false; | ||
@@ -54,15 +53,5 @@ this.fg = this.bg = null; | ||
}, | ||
enumerable: true, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(AnsiUp.prototype, "escape_for_html", { | ||
get: function () { | ||
return this._escape_for_html; | ||
}, | ||
set: function (arg) { | ||
this._escape_for_html = arg; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(AnsiUp.prototype, "url_whitelist", { | ||
@@ -75,3 +64,3 @@ get: function () { | ||
}, | ||
enumerable: true, | ||
enumerable: false, | ||
configurable: true | ||
@@ -126,3 +115,3 @@ }); | ||
AnsiUp.prototype.escape_txt_for_html = function (txt) { | ||
return txt.replace(/[&<>]/gm, function (str) { | ||
return txt.replace(/[&<>"']/gm, function (str) { | ||
if (str === "&") | ||
@@ -134,2 +123,6 @@ return "&"; | ||
return ">"; | ||
if (str === "\"") | ||
return """; | ||
if (str === "'") | ||
return "'"; | ||
}); | ||
@@ -349,4 +342,3 @@ }; | ||
return txt; | ||
if (this._escape_for_html) | ||
txt = this.escape_txt_for_html(txt); | ||
txt = this.escape_txt_for_html(txt); | ||
if (!fragment.bold && fragment.fg === null && fragment.bg === null) | ||
@@ -353,0 +345,0 @@ return txt; |
@@ -53,3 +53,3 @@ /* ansi_up.js | ||
{ | ||
VERSION = "4.0.4"; | ||
VERSION = "5.0.0"; | ||
@@ -70,3 +70,2 @@ // | ||
private _use_classes:boolean; | ||
private _escape_for_html; | ||
@@ -87,3 +86,2 @@ private _csi_regex:RegExp; | ||
this._use_classes = false; | ||
this._escape_for_html = true; | ||
@@ -108,12 +106,2 @@ this.bold = false; | ||
set escape_for_html(arg:boolean) | ||
{ | ||
this._escape_for_html = arg; | ||
} | ||
get escape_for_html():boolean | ||
{ | ||
return this._escape_for_html; | ||
} | ||
set url_whitelist(arg:{}) | ||
@@ -190,6 +178,8 @@ { | ||
{ | ||
return txt.replace(/[&<>]/gm, (str) => { | ||
if (str === "&") return "&"; | ||
if (str === "<") return "<"; | ||
if (str === ">") return ">"; | ||
return txt.replace(/[&<>"']/gm, (str) => { | ||
if (str === "&") return "&"; | ||
if (str === "<") return "<"; | ||
if (str === ">") return ">"; | ||
if (str === "\"") return """; | ||
if (str === "'") return "'"; | ||
}); | ||
@@ -639,4 +629,3 @@ } | ||
if (this._escape_for_html) | ||
txt = this.escape_txt_for_html(txt); | ||
txt = this.escape_txt_for_html(txt); | ||
@@ -643,0 +632,0 @@ // If colors not set, default style is used |
@@ -33,3 +33,2 @@ export interface AU_Color { | ||
private _use_classes; | ||
private _escape_for_html; | ||
private _csi_regex; | ||
@@ -41,5 +40,6 @@ private _osc_st; | ||
constructor(); | ||
use_classes: boolean; | ||
escape_for_html: boolean; | ||
url_whitelist: {}; | ||
set use_classes(arg: boolean); | ||
get use_classes(): boolean; | ||
set url_whitelist(arg: {}); | ||
get url_whitelist(): {}; | ||
private setup_palettes; | ||
@@ -46,0 +46,0 @@ private escape_txt_for_html; |
{ | ||
"name": "ansi_up", | ||
"version": "4.0.4", | ||
"version": "5.0.0", | ||
"description": "Convert ansi sequences in strings to colorful HTML", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -122,10 +122,2 @@ # ansi_up.js | ||
#### escape_for_html | ||
(default: true) | ||
This does the minimum escaping of text to make it compliant with HTML. | ||
In particular, the '&','<', and '>' characters are escaped. It is | ||
** highly ** recommended that you do not set this to false. It will open | ||
the door security vulnerabilities. | ||
#### use_classes | ||
@@ -144,9 +136,6 @@ (default: false) | ||
In general, the ansi_to_html *should* emit HTML when invoked with a non-empty string. | ||
The only exceptions are an incomplete ESC sequence or an incomplete escaped URL. | ||
For those cases, the library will buffer the escape or the sequence for the escaped URL. | ||
In general, the ansi_to_html *should* emit HTML output when invoked with a non-empty string. | ||
The only exceptions are an incomplete ESC sequence or an incomplete OSC URL sequence. | ||
For those cases, the library will buffer (not emit output), until it receives input that completes those sequences. | ||
The library is also stateful. If a color is set in a prior invocation, then it will | ||
continue to emit that color in further invocations until the color/SGR attribute is changed. | ||
### Example of a Use Case | ||
@@ -153,0 +142,0 @@ |
@@ -115,3 +115,3 @@ var AU = require('../ansi_up'); | ||
var start = "<&>/\\'\""; | ||
var expected = "<&>/\\'\""; | ||
var expected = "<&>/\\'""; | ||
@@ -127,131 +127,2 @@ var au = new AnsiUp(); | ||
describe('escape_for_html off', function () { | ||
describe('ampersands', function () { | ||
it('should escape a single ampersand', function () { | ||
var start = "&"; | ||
var expected = "&"; | ||
var au = new AnsiUp(); | ||
au.escape_for_html = false; | ||
var l = au.ansi_to_html(start); | ||
l.should.eql(expected); | ||
}); | ||
it('should escape some text with ampersands', function () { | ||
var start = "abcd&efgh"; | ||
var expected = "abcd&efgh"; | ||
var au = new AnsiUp(); | ||
au.escape_for_html = false; | ||
var l = au.ansi_to_html(start); | ||
l.should.eql(expected); | ||
}); | ||
it('should escape multiple ampersands', function () { | ||
var start = " & & "; | ||
var expected = " & & "; | ||
var au = new AnsiUp(); | ||
au.escape_for_html = false; | ||
var l = au.ansi_to_html(start); | ||
l.should.eql(expected); | ||
}); | ||
it('should escape an already escaped ampersand', function () { | ||
var start = " & "; | ||
var expected = " & "; | ||
var au = new AnsiUp(); | ||
au.escape_for_html = false; | ||
var l = au.ansi_to_html(start); | ||
l.should.eql(expected); | ||
}); | ||
}); | ||
describe('less-than', function () { | ||
it('should escape a single less-than', function () { | ||
var start = "<"; | ||
var expected = "<"; | ||
var au = new AnsiUp(); | ||
au.escape_for_html = false; | ||
var l = au.ansi_to_html(start); | ||
l.should.eql(expected); | ||
}); | ||
it('should escape some text with less-thans', function () { | ||
var start = "abcd<efgh"; | ||
var expected = "abcd<efgh"; | ||
var au = new AnsiUp(); | ||
au.escape_for_html = false; | ||
var l = au.ansi_to_html(start); | ||
l.should.eql(expected); | ||
}); | ||
it('should escape multiple less-thans', function () { | ||
var start = " < < "; | ||
var expected = " < < "; | ||
var au = new AnsiUp(); | ||
au.escape_for_html = false; | ||
var l = au.ansi_to_html(start); | ||
l.should.eql(expected); | ||
}); | ||
}); | ||
describe('greater-than', function () { | ||
it('should escape a single greater-than', function () { | ||
var start = ">"; | ||
var expected = ">"; | ||
var au = new AnsiUp(); | ||
au.escape_for_html = false; | ||
var l = au.ansi_to_html(start); | ||
l.should.eql(expected); | ||
}); | ||
it('should escape some text with greater-thans', function () { | ||
var start = "abcd>efgh"; | ||
var expected = "abcd>efgh"; | ||
var au = new AnsiUp(); | ||
au.escape_for_html = false; | ||
var l = au.ansi_to_html(start); | ||
l.should.eql(expected); | ||
}); | ||
it('should escape multiple greater-thans', function () { | ||
var start = " > > "; | ||
var expected = " > > "; | ||
var au = new AnsiUp(); | ||
au.escape_for_html = false; | ||
var l = au.ansi_to_html(start); | ||
l.should.eql(expected); | ||
}); | ||
}); | ||
describe('mixed characters', function () { | ||
it('should escape a mix of characters that require escaping', function () { | ||
var start = "<&>/\\'\""; | ||
var expected = "<&>/\\'\""; | ||
var au = new AnsiUp(); | ||
au.escape_for_html = false; | ||
var l = au.ansi_to_html(start); | ||
l.should.eql(expected); | ||
}); | ||
}); | ||
}); | ||
describe('hyperlinks', function () { | ||
@@ -258,0 +129,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
273266
-97.71%28
-17.65%2149
-14.82%191
-5.45%