wrap-ansi known bugs

npm

9 known bugs in wrap-ansi, with affected versions, fixes and workarounds. Sourced from upstream issue trackers.

9
bugs
Known bugs
SeverityAffectedFixed inTitleStatusSource
mediumany\u2014
Setting wordWrap to false does not always result in correct wrapping
With the following piece of text as input > 12345678\n901234567890 12345 And, setting `wordWrap` to false with a character count of `5` currently results in the following output > 12345678 > 901234567890 > 12345 The reason for this is that [this line](https://github.com/chalk/wrap-ansi/blob/master/index.js#L134) does not take the `wordWrap` setting into account. Fix is coming up!
fixedgithub:18
mediumany\u2014
Does not wrap a series of whitespace
<!-- Issuehunt Badges --> [<img alt="Issuehunt badges" src="https://issuehunt.io/r/chalk/wrap-ansi/issues/23/badge.svg" />](https://issuehunt.io/r/chalk/wrap-ansi/issues/23) <!-- /Issuehunt Badges --> ```js wrap(' ', 2, { trim: false }) ' ' // actual ' \n ' // expected ``` Adding `hard` does not change the behaviour. <!-- Issuehunt content --> > [stroncium](https://issuehunt.io/u/stroncium) earned $40.00 by resolving this issue! > - Checkout the [Issuehunt explorer](https://issuehunt.io/r/chalk/wrap-ansi/) to discover more funded issues. > - Need some help from other developers? [Add your repositories](https://issuehunt.io/r/new) on Issuehunt to raise funds. <!-- /Issuehunt content-->
fixedgithub:23
medium2.1.0\u2014
Difference in output between 2.1.0 and 3.0.1
<!-- Issuehunt Badges --> [<img alt="Issuehunt badges" src="https://issuehunt.io/r/chalk/wrap-ansi/issues/24/badge.svg" />](https://issuehunt.io/r/chalk/wrap-ansi/issues/24) <!-- /Issuehunt Badges --> I have the following minimal test case: ```js 'use strict' const wrap = require('wrap-ansi'); const chalk = require('chalk'); const srcString = chalk.blue(' 1 2 '); console.log('"' + wrap(srcString, 20, {hard: true}) + '"'); console.log('"' + wrap(srcString, 20, {hard: true, trim: false}) + '"'); ``` Note that srcString has 2 spaces before, between and after the numbers. Against v2.1.0: The test prints the same output twice (`trim: false` is ignored). The output is `"1 2 "` - both spaces before the '1' were removed. If color terminal is disabled the spaces after the '2' are also removed. Against v3.0.1: The first line prints with a single space between the numbers, and if color is enabled a single space after the numbers. The second line prints the original string if color is enabled, if color is disabled it prints an extra space before the string (3 spaces total before the '1'). This was found when trying to update cliui to use v3.0.1. I don't know what the correct behavior should be. <!-- Issuehunt content --> > [stroncium](https://issuehunt.io/u/stroncium) earned $40.00 by resolving this issue! > - Checkout the [Issuehunt explorer](https://issuehunt.io/r/chalk/wrap-ansi/) to discover more funded issues. > - Need some help from other developers? [Add your repositories](https://issuehunt.io/r/new) on Issuehunt to raise funds. <!-- /Issuehunt content-->
fixedgithub:24
mediumany\u2014
Off by one if trimming is disabled
<!-- Issuehunt Badges --> [<img alt="Issuehunt badges" src="https://issuehunt.io/r/chalk/wrap-ansi/issues/25/badge.svg" />](https://issuehunt.io/r/chalk/wrap-ansi/issues/25) <!-- /Issuehunt Badges --> If trimming is disabled, and you're wrapping a text a say length 3, and there's a whitespace right where the wrap should occur, the whitespace remains and the line break is appended to it. This results in the line being one char too long: ```js console.log(JSON.stringify(trim('foo bar', 3))) // => "foo\nbar" console.log(JSON.stringify(trim('foo bar', 3, {trim: false}))) // => "foo \nbar" ``` <!-- Issuehunt content --> > [stroncium](https://issuehunt.io/u/stroncium) earned $40.00 by resolving this issue! > - Checkout the [Issuehunt explorer](https://issuehunt.io/r/chalk/wrap-ansi/) to discover more funded issues. > - Need some help from other developers? [Add your repositories](https://issuehunt.io/r/new) on Issuehunt to raise funds. <!-- /Issuehunt content-->
fixedgithub:25
medium2.3.0\u2014
Incorrect leading spaces
<!-- Issuehunt Badges --> [<img alt="Issuehunt badges" src="https://issuehunt.io/r/chalk/wrap-ansi/issues/26/badge.svg" />](https://issuehunt.io/r/chalk/wrap-ansi/issues/26) <!-- /Issuehunt Badges --> with version 2.3.0: ```js // 1 leading space require('wrap-ansi')(' a ', process.stdout.columns, {trim: false}) ``` Out: ```js // 2 leading spaces ' a ' ``` <!-- Issuehunt content --> > [stroncium](https://issuehunt.io/u/stroncium) earned $80.00 by resolving this issue! > - Checkout the [Issuehunt explorer](https://issuehunt.io/r/chalk/wrap-ansi/) to discover more funded issues. > - Need some help from other developers? [Add your repositories](https://issuehunt.io/r/new) on Issuehunt to raise funds. <!-- /Issuehunt content-->
fixedgithub:26
mediumany\u2014
leading space removed when line starts with ansi escape
<!-- Issuehunt Badges --> [<img alt="Issuehunt badges" src="https://issuehunt.io/r/chalk/wrap-ansi/issues/27/badge.svg" />](https://issuehunt.io/r/chalk/wrap-ansi/issues/27) <!-- /Issuehunt Badges --> ```js const chalk = require('chalk'); const wrapAnsi = require('wrap-ansi'); const s = chalk.bgGreen(` ${chalk.black('OK')} `); console.log(s); console.log(wrapAnsi(s, 100, { trim: false })); ``` ![screen shot 2018-03-27 at 1 34 18 pm](https://user-images.githubusercontent.com/15624/37984190-9b3659be-31c3-11e8-891a-667c5c2a8edf.png) <!-- Issuehunt content --> > [stroncium](https://issuehunt.io/u/stroncium) earned $60.00 by resolving this issue! > - Checkout the [Issuehunt explorer](https://issuehunt.io/r/chalk/wrap-ansi/) to discover more funded issues. > - Need some help from other developers? [Add your repositories](https://issuehunt.io/r/new) on Issuehunt to raise funds. <!-- /Issuehunt content-->
fixedgithub:27
mediumany\u2014
URLs larger than column always begin on new line
I've only noticed this happen with URLs and only with `hard: true`. Even with `wordWrap: false` it still happens as long as `hard: true` is passed. --- Normal 'word': ```javascript > const wrapAnsi = require('wrap-ansi'); > console.log(wrapAnsi('hi, this IsAReallyLongWordButIDoNotKnowHowItShouldBehave', 32, {hard: true})); ``` ``` hi, this IsAReallyLongWordButIDo NotKnowHowItShouldBehave ``` ✅ --- Hyperlink: ```javascript > const wrapAnsi = require('wrap-ansi'); > console.log(wrapAnsi('hi, this https://IsAReallyLongWordButIDoNotKnowHowItShouldBehave.com', 32, {hard: true})); ``` ``` hi, this https://IsAReallyLongWordButIDoN otKnowHowItShouldBehave.com ``` ❌
fixedgithub:38
mediumany\u2014
Inconsistant styling for strings with background and foreground.
Something similar to slice-ansi: https://github.com/chalk/slice-ansi/issues/22 My use case is wrapping strings to terminal width, and only showing some lines. The following example works as expected: ```node var string = chalk.bgGreen("test"); var wrapped = wrapAnsi(string, 2, {hard: true, trim: false, wordWrap: false}); var lines = wrapped.split("\n"); console.log(lines[0]) console.log(lines) ``` You can see that the background is properly ended for each line, this is the behavior I expect when I try background and foreground: ```node [ '\u001b[42mte\u001b[49m', '\u001b[42mst\u001b[49m' ] ``` When you add a foreground however, the background never stops. ```node var string = chalk.bgGreen.black('test'); var wrapped = wrapAnsi(string, 2, {hard: true, trim: false, wordWrap: false}); var lines = wrapped.split("\n"); console.log(lines[0]) console.log(lines) ``` Result: ![image](https://user-images.githubusercontent.com/39616756/89413463-05142b80-d768-11ea-9f71-d3f9a2faab59.png) ```node [ '\u001b[42m\u001b[30mte\u001b[39m', '\u001b[30mst\u001b[39m\u001b[49m' ] ``` You can see that the inner ansi style is applied and ended per line, but that the outer style is applied only once. I would expect the behavior to be consistent with the previous example. Thanks!
fixedgithub:43
mediumany\u2014
Malicious code in wrap-ansi (npm)
The package was compromised and malicious code added. --- _-= Per source details. Do not edit below this line.=-_ ## Source: ghsa-malware (9e58bb76dd73218635e5f6badd1c9693b827a8eb1be48d0bac75d6f8f85d4b53) Any computer that has this package installed or running should be considered fully compromised. All secrets and keys stored on that computer should be rotated immediately from a different computer. The package should be removed, but as full control of the computer may have been given to an outside entity, there is no guarantee that removing the package will remove all malicious software resulting from installing it.
openosv:MAL-2025-46983
API access

Get this data programmatically \u2014 free, no authentication.

curl https://depscope.dev/api/bugs/npm/wrap-ansi
wrap-ansi bugs — known issues per version | DepScope | DepScope