Skip to content

Commit

Permalink
fix recursive call to echo in renderHandler #733
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Sep 6, 2024
1 parent dcfddbe commit aee44ef
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 30 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
## 2.43.0
### Breaking
* echo of undefined or Promise that resolve to undefined no longer display string undefined
### Features
* add support for `--rows` CSS custom property [#956](https://github.com/jcubic/jquery.terminal/issues/956)
* add aborting signals [#940](https://github.com/jcubic/jquery.terminal/issues/940)
Expand All @@ -7,6 +9,7 @@
* don't reflow the reflow the cursor on update [#932](https://github.com/jcubic/jquery.terminal/issues/932)
* fix unexpected uncaught exceptions in promises
* fix skip/skip_stop return value and add types
* fix recursive call to echo in renderHandler [#733](https://github.com/jcubic/jquery.terminal/issues/733)

## 2.42.2
### Bugfix
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[![npm](https://img.shields.io/badge/npm-DEV-blue.svg)](https://www.npmjs.com/package/jquery.terminal)
![bower](https://img.shields.io/badge/bower-DEV-yellow.svg)
[![Build and test](https://github.com/jcubic/jquery.terminal/actions/workflows/build.yaml/badge.svg?branch=devel&event=push)](https://github.com/jcubic/jquery.terminal/actions/workflows/build.yaml)
[![Coverage Status](https://coveralls.io/repos/github/jcubic/jquery.terminal/badge.svg?branch=devel&51f64e9c8e34766fe0242bc865242ed2)](https://coveralls.io/github/jcubic/jquery.terminal?branch=devel)
[![Coverage Status](https://coveralls.io/repos/github/jcubic/jquery.terminal/badge.svg?branch=devel&f35aec91fb68f5c8cdbfffb6d6292e3a)](https://coveralls.io/github/jcubic/jquery.terminal?branch=devel)
![NPM Downloads](https://img.shields.io/npm/dm/jquery.terminal.svg?style=flat)
[![jsDelivr Downloads](https://data.jsdelivr.com/v1/package/npm/jquery.terminal/badge?style=rounded&n=1)](https://www.jsdelivr.com/package/npm/jquery.terminal)
[![Paid Support](https://img.shields.io/badge/paid-support-354465.svg)](https://support.jcubic.pl/)
Expand Down
4 changes: 2 additions & 2 deletions __tests__/terminal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6421,9 +6421,9 @@ describe('Terminal plugin', function() {
term.clear().echo(input);
expect(output().join('\n')).toEqual(input);
});
it('should print undefined', function() {
it('should not print undefined', function() {
term.clear().echo(undefined);
expect(output().join('\n')).toEqual('undefined');
expect(output().join('\n')).toEqual('');
});
it('should print value from function that return promise', function(done) {
var term = $('<div/>').terminal();
Expand Down
35 changes: 27 additions & 8 deletions js/jquery.terminal-2.42.2.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
*
* broken image by Sophia Bai from the Noun Project (CC-BY)
*
* Date: Fri, 06 Sep 2024 00:31:42 +0000
* Date: Fri, 06 Sep 2024 14:16:31 +0000
*/
/* global define, Map, BigInt */
/* eslint-disable */
Expand Down Expand Up @@ -1104,6 +1104,16 @@
return defer.promise();
}
// -----------------------------------------------------------------------
function always(value, callback) {
if (is_function(ret.finally)) {
return ret.finally(callback);
}
if (is_function(ret.always)) {
return ret.always(callback);
}
return value;
}
// -----------------------------------------------------------------------
function unpromise(value, callback, error) {
if (value !== undefined) {
if (is_promise(value)) {
Expand Down Expand Up @@ -5313,7 +5323,7 @@
// -------------------------------------------------------------------------
$.terminal = {
version: 'DEV',
date: 'Fri, 06 Sep 2024 00:31:42 +0000',
date: 'Fri, 06 Sep 2024 14:16:31 +0000',
// colors from https://www.w3.org/wiki/CSS/Properties/color/keywords
color_names: [
'transparent', 'currentcolor', 'black', 'silver', 'gray', 'white',
Expand Down Expand Up @@ -7684,7 +7694,13 @@
if (ret === false) {
return false;
}
if (typeof ret === 'string' || is_node(ret) || is_promise(ret)) {
var was_promise = is_promise(ret);
if (was_promise) {
return always(ret, function() {
recursive_render = false;
});
}
if (typeof ret === 'string' || is_node(ret)) {
return ret;
} else {
return value;
Expand All @@ -7695,7 +7711,9 @@
format_stack_trace(e.stack)
].join('\n');
} finally {
recursive_render = false;
if (!was_promise) {
recursive_render = false;
}
}
});
}
Expand Down Expand Up @@ -11018,7 +11036,7 @@
value = arg.bind(self);
} else if (typeof arg === 'undefined') {
if (arg_defined) {
value = String(arg);
return self;
} else {
value = '';
}
Expand All @@ -11033,11 +11051,12 @@
echo_promise = true;
}
unpromise(value, function(value) {
if (is_promise(ret) && value === false) {
if (typeof value === 'undefined' ||
(is_promise(ret) && value === false)) {
return;
}
if (render(value, locals)) {
return self;
return;
}
var index = lines.length();
var last_newline = lines.has_newline();
Expand Down Expand Up @@ -11100,7 +11119,7 @@
}
}
var is_animation = options && options.typing;
if (echo_promise) {
if (echo_promise && !recursive_render) {
var args = [arg, options];
if (is_animation) {
args.push(d);
Expand Down
4 changes: 2 additions & 2 deletions js/jquery.terminal-2.42.2.min.js

Large diffs are not rendered by default.

31 changes: 25 additions & 6 deletions js/jquery.terminal-src.js
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,16 @@
return defer.promise();
}
// -----------------------------------------------------------------------
function always(value, callback) {
if (is_function(ret.finally)) {

Check failure on line 1108 in js/jquery.terminal-src.js

View workflow job for this annotation

GitHub Actions / build

'ret' is not defined
return ret.finally(callback);

Check failure on line 1109 in js/jquery.terminal-src.js

View workflow job for this annotation

GitHub Actions / build

'ret' is not defined
}
if (is_function(ret.always)) {

Check failure on line 1111 in js/jquery.terminal-src.js

View workflow job for this annotation

GitHub Actions / build

'ret' is not defined
return ret.always(callback);

Check failure on line 1112 in js/jquery.terminal-src.js

View workflow job for this annotation

GitHub Actions / build

'ret' is not defined
}
return value;
}
// -----------------------------------------------------------------------
function unpromise(value, callback, error) {
if (value !== undefined) {
if (is_promise(value)) {
Expand Down Expand Up @@ -7684,7 +7694,13 @@
if (ret === false) {
return false;
}
if (typeof ret === 'string' || is_node(ret) || is_promise(ret)) {
var was_promise = is_promise(ret);
if (was_promise) {
return always(ret, function() {
recursive_render = false;
});
}
if (typeof ret === 'string' || is_node(ret)) {
return ret;
} else {
return value;
Expand All @@ -7695,7 +7711,9 @@
format_stack_trace(e.stack)
].join('\n');
} finally {
recursive_render = false;
if (!was_promise) {
recursive_render = false;
}
}
});
}
Expand Down Expand Up @@ -11018,7 +11036,7 @@
value = arg.bind(self);
} else if (typeof arg === 'undefined') {
if (arg_defined) {
value = String(arg);
return self;
} else {
value = '';
}
Expand All @@ -11033,11 +11051,12 @@
echo_promise = true;
}
unpromise(value, function(value) {
if (is_promise(ret) && value === false) {
if (typeof value === 'undefined' ||
(is_promise(ret) && value === false)) {
return;
}
if (render(value, locals)) {
return self;
return;
}
var index = lines.length();
var last_newline = lines.has_newline();
Expand Down Expand Up @@ -11100,7 +11119,7 @@
}
}
var is_animation = options && options.typing;
if (echo_promise) {
if (echo_promise && !recursive_render) {
var args = [arg, options];
if (is_animation) {
args.push(d);
Expand Down
35 changes: 27 additions & 8 deletions js/jquery.terminal.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
*
* broken image by Sophia Bai from the Noun Project (CC-BY)
*
* Date: Fri, 06 Sep 2024 00:31:42 +0000
* Date: Fri, 06 Sep 2024 14:16:31 +0000
*/
/* global define, Map, BigInt */
/* eslint-disable */
Expand Down Expand Up @@ -1104,6 +1104,16 @@
return defer.promise();
}
// -----------------------------------------------------------------------
function always(value, callback) {
if (is_function(ret.finally)) {
return ret.finally(callback);
}
if (is_function(ret.always)) {
return ret.always(callback);
}
return value;
}
// -----------------------------------------------------------------------
function unpromise(value, callback, error) {
if (value !== undefined) {
if (is_promise(value)) {
Expand Down Expand Up @@ -5313,7 +5323,7 @@
// -------------------------------------------------------------------------
$.terminal = {
version: 'DEV',
date: 'Fri, 06 Sep 2024 00:31:42 +0000',
date: 'Fri, 06 Sep 2024 14:16:31 +0000',
// colors from https://www.w3.org/wiki/CSS/Properties/color/keywords
color_names: [
'transparent', 'currentcolor', 'black', 'silver', 'gray', 'white',
Expand Down Expand Up @@ -7684,7 +7694,13 @@
if (ret === false) {
return false;
}
if (typeof ret === 'string' || is_node(ret) || is_promise(ret)) {
var was_promise = is_promise(ret);
if (was_promise) {
return always(ret, function() {
recursive_render = false;
});
}
if (typeof ret === 'string' || is_node(ret)) {
return ret;
} else {
return value;
Expand All @@ -7695,7 +7711,9 @@
format_stack_trace(e.stack)
].join('\n');
} finally {
recursive_render = false;
if (!was_promise) {
recursive_render = false;
}
}
});
}
Expand Down Expand Up @@ -11018,7 +11036,7 @@
value = arg.bind(self);
} else if (typeof arg === 'undefined') {
if (arg_defined) {
value = String(arg);
return self;
} else {
value = '';
}
Expand All @@ -11033,11 +11051,12 @@
echo_promise = true;
}
unpromise(value, function(value) {
if (is_promise(ret) && value === false) {
if (typeof value === 'undefined' ||
(is_promise(ret) && value === false)) {
return;
}
if (render(value, locals)) {
return self;
return;
}
var index = lines.length();
var last_newline = lines.has_newline();
Expand Down Expand Up @@ -11100,7 +11119,7 @@
}
}
var is_animation = options && options.typing;
if (echo_promise) {
if (echo_promise && !recursive_render) {
var args = [arg, options];
if (is_animation) {
args.push(d);
Expand Down
4 changes: 2 additions & 2 deletions js/jquery.terminal.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/jquery.terminal.min.js.map

Large diffs are not rendered by default.

0 comments on commit aee44ef

Please sign in to comment.