Skip to content

Commit

Permalink
fix processing Hex HTML entities #992
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Dec 13, 2024
1 parent 85aec29 commit 7483c09
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* fix `terminal::login()` when user already authenticated [#980](https://github.com/jcubic/jquery.terminal/issues/980)
* improve mobile support
* ignore empty command in Pipe extension [#984](https://github.com/jcubic/jquery.terminal/issues/984)
* fix processing Hex HTML entities [#992](https://github.com/jcubic/jquery.terminal/issues/992)

## 2.44.1
### 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&26ea018b3abc2f72f4987018534fef0c)](https://coveralls.io/github/jcubic/jquery.terminal?branch=devel)
[![Coverage Status](https://coveralls.io/repos/github/jcubic/jquery.terminal/badge.svg?branch=devel&e31addf398172b261ad412bde3188469)](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
10 changes: 10 additions & 0 deletions __tests__/terminal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,16 @@ describe('Terminal utils', function() {
});
});
});
describe('$.terminal.length', function() {
it('shoud count html entitites', () => {
const input = '▲▼\';
expect($.terminal.length(input)).toBe(3);
});
it('should count emoji', () => {
const input = '💩💩💩';
expect($.terminal.length(input)).toBe(3);
});
});
describe('$.terminal.is_formatting', function() {
it('should detect terminal formatting', function() {
var formattings = [
Expand Down
2 changes: 1 addition & 1 deletion css/emoji.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion css/jquery.terminal.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Copyright (c) 2011-2024 Jakub T. Jankiewicz <https://jcubic.pl/me>
* Released under the MIT license
*
* Date: Mon, 18 Nov 2024 23:03:38 +0000
* Date: Fri, 13 Dec 2024 15:03:29 +0000
*/
.terminal .terminal-output .format, .cmd .format,
.cmd-prompt, .cmd-prompt div {
Expand Down
2 changes: 1 addition & 1 deletion css/jquery.terminal.min.css

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions js/jquery.terminal-src.js
Original file line number Diff line number Diff line change
Expand Up @@ -4801,8 +4801,13 @@
};
// -------------------------------------------------------------------------
function render_entities(str) {
return str.replace(/&#(x?)([0-9]+);/g, function(_, hex, code) {
code = parseInt(code, hex ? 16 : 10);
return str.replace(/&#(?:x([0-9a-f]+)|([0-9]+));/gi, function(_, hex, dec) {
var code;
if (hex) {
code = parseInt(hex, 16);
} else {
code = parseInt(dec, 10);
}
return String.fromCharCode(code);
}).replace(/(&[^;]+;)/g, function(_, entity) {
return entities[entity] || entity;
Expand Down
13 changes: 9 additions & 4 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: Mon, 09 Dec 2024 20:30:04 +0000
* Date: Fri, 13 Dec 2024 15:04:35 +0000
*/
/* global define, Map, BigInt */
/* eslint-disable */
Expand Down Expand Up @@ -4801,8 +4801,13 @@
};
// -------------------------------------------------------------------------
function render_entities(str) {
return str.replace(/&#(x?)([0-9]+);/g, function(_, hex, code) {
code = parseInt(code, hex ? 16 : 10);
return str.replace(/&#(?:x([0-9a-f]+)|([0-9]+));/gi, function(_, hex, dec) {
var code;
if (hex) {
code = parseInt(hex, 16);
} else {
code = parseInt(dec, 10);
}
return String.fromCharCode(code);
}).replace(/(&[^;]+;)/g, function(_, entity) {
return entities[entity] || entity;
Expand Down Expand Up @@ -5402,7 +5407,7 @@
// -------------------------------------------------------------------------
$.terminal = {
version: 'DEV',
date: 'Mon, 09 Dec 2024 20:30:04 +0000',
date: 'Fri, 13 Dec 2024 15:04:35 +0000',
// colors from https://www.w3.org/wiki/CSS/Properties/color/keywords
color_names: [
'transparent', 'currentcolor', 'black', 'silver', 'gray', 'white',
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 7483c09

Please sign in to comment.