Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Difference in output between 2.1.0 and 3.0.1 #24

Closed
coreyfarrell opened this issue Dec 26, 2017 · 5 comments · Fixed by #30
Closed

Difference in output between 2.1.0 and 3.0.1 #24

coreyfarrell opened this issue Dec 26, 2017 · 5 comments · Fixed by #30
Labels
bug 🎁 Rewarded on Issuehunt This issue has been rewarded on Issuehunt help wanted

Comments

@coreyfarrell
Copy link
Contributor

coreyfarrell commented Dec 26, 2017

Issuehunt badges

I have the following minimal test case:

'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.

stroncium earned $40.00 by resolving this issue!

@watson
Copy link

watson commented Dec 29, 2017

The issue can be boiled down to this:

var text = 'foo    bar'
console.log(JSON.stringify(text)) // => "foo    bar"
var r1 = wrap(text, 42)
console.log(JSON.stringify(r1))   // => "foo bar"
var r2 = wrap(text, 42, {trim: false})
console.log(JSON.stringify(r2))   // => "foo    bar"

I'm not sure from reading the readme if this is the intended result, or if this is a bug. But if it's the intended result, I think trim: true it's the wrong default as it's very counter intuitive.

@watson
Copy link

watson commented Dec 29, 2017

For reference, this is where the trimming happens:

a8c3423#diff-168726dbe96b3ce427e7fedce31bb0bcR114

@sindresorhus
Copy link
Member

Confirmed. It should only trim leading and trailing whitespace on actual wrapped lines. See #9 and #17 for context.

@IssueHuntBot
Copy link

@IssueHunt has funded $40.00 to this issue. See it on IssueHunt

stroncium added a commit to stroncium/wrap-ansi that referenced this issue Feb 27, 2019
sindresorhus pushed a commit that referenced this issue Mar 3, 2019
Fixes #23
Fixes #24
Fixes #25
Fixes #26
Fixes #27
@IssueHuntBot
Copy link

@sindresorhus has rewarded $36.00 to @stroncium. See it on IssueHunt

  • 💰 Total deposit: $40.00
  • 🎉 Repository reward(0%): $0.00
  • 🔧 Service fee(10%): $4.00

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🎁 Rewarded on Issuehunt This issue has been rewarded on Issuehunt help wanted
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants