Skip to content

Commit

Permalink
string: fix maximum output length
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Mar 17, 2020
1 parent f105d52 commit bb6f747
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,7 @@

## Trunk

* string: fix maximum output length
* package: update author url

## Version 0.5.2
Expand Down
4 changes: 1 addition & 3 deletions lib/printf.js
Expand Up @@ -281,7 +281,6 @@ Formatter.prototype.format = function(/*mixed...*/ filler){
this.formatObject(token);
}
this.fitField(token);

str += '' + token.arg;
}
}
Expand Down Expand Up @@ -435,7 +434,7 @@ Formatter.prototype.zeroPad = function(token, /*Int*/ length) {
};
Formatter.prototype.fitField = function(token) {
if(token.maxWidth >= 0 && token.arg.length > token.maxWidth){
return token.arg.substring(0, token.maxWidth);
token.arg = token.arg.substring(0, token.maxWidth);
}
if(token.zeroPad){
this.zeroPad(token, token.minWidth);
Expand All @@ -456,7 +455,6 @@ Formatter.prototype.spacePad = function(token, /*Int*/ length) {
token.arg = (token.rightJustify) ? token.arg + this._spaces10.substring(0, pad) : this._spaces10.substring(0, pad) + token.arg;
};


module.exports = function(){
var args = Array.prototype.slice.call(arguments),
stream, format;
Expand Down
13 changes: 13 additions & 0 deletions package.json
Expand Up @@ -21,6 +21,19 @@
"LLeo <lleoem@gmail.com>",
"Derrell Lipman <https://github.com/derrell>"
],
"coffeelintConfig": {
"indentation": {
"level": "error",
"value": 2
},
"line_endings": {
"level": "error",
"value": "unix"
},
"max_line_length": {
"level": "ignore"
}
},
"main": "./lib/printf",
"types": "./lib/printf.d.ts",
"engines": {
Expand Down
1 change: 1 addition & 0 deletions test/printf.coffee
Expand Up @@ -65,6 +65,7 @@ describe 'sprintf', ->
printf('%+6.2f', 42.8952).should.eql '+42.90'
printf('%5.10f', 42.8952).should.eql '42.8952000000'
printf('%1.4g', 1.06800e-10).should.eql '1.068e-10'
printf('%.3s', 'Hello').should.eql 'Hel' # Maximum output length

it 'Bases', ->
printf('%c', 0x7f).should.eql ''
Expand Down

0 comments on commit bb6f747

Please sign in to comment.