| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 1b06c1e commit e457d89
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -222,8 +222,8 @@ function _copy(source, target, targetStart, sourceStart, sourceEnd) { | |||
| 222 | 222 | sourceStart = 0; | |
| 223 | 223 | } else { | |
| 224 | 224 | sourceStart = toInteger(sourceStart, 0); | |
| 225 | - if (sourceStart < 0) | ||
| 226 | - throw new ERR_OUT_OF_RANGE('sourceStart', '>= 0', sourceStart); | ||
| 225 | + if (sourceStart < 0 || sourceStart > source.length) | ||
| 226 | + throw new ERR_OUT_OF_RANGE('sourceStart', `>= 0 && <= ${source.length}`, sourceStart); | ||
| 227 | 227 | } | |
| 228 | 228 | ||
| 229 | 229 | if (sourceEnd === undefined) { | |
@@ -237,12 +237,6 @@ function _copy(source, target, targetStart, sourceStart, sourceEnd) { | |||
| 237 | 237 | if (targetStart >= target.length || sourceStart >= sourceEnd) | |
| 238 | 238 | return 0; | |
| 239 | 239 | ||
| 240 | - if (sourceStart > source.length) { | ||
| 241 | - throw new ERR_OUT_OF_RANGE('sourceStart', | ||
| 242 | - `<= ${source.length}`, | ||
| 243 | - sourceStart); | ||
| 244 | - } | ||
| 245 | - | ||
| 246 | 240 | return _copyActual(source, target, targetStart, sourceStart, sourceEnd); | |
| 247 | 241 | } | |
| 248 | 242 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -124,7 +124,7 @@ b.copy(Buffer.alloc(0), 1, 1, 1); | |||
| 124 | 124 | b.copy(Buffer.alloc(1), 1, 1, 1); | |
| 125 | 125 | ||
| 126 | 126 | // Try to copy 0 bytes from past the end of the source buffer | |
| 127 | - b.copy(Buffer.alloc(1), 0, 2048, 2048); | ||
| 127 | + b.copy(Buffer.alloc(1), 0, 1024, 1024); | ||
| 128 | 128 | ||
| 129 | 129 | // Testing for smart defaults and ability to pass string values as offset | |
| 130 | 130 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -155,8 +155,15 @@ assert.throws( | |||
| 155 | 155 | { | |
| 156 | 156 | code: 'ERR_OUT_OF_RANGE', | |
| 157 | 157 | name: 'RangeError', | |
| 158 | - message: 'The value of "sourceStart" is out of range. ' + | ||
| 159 | - 'It must be >= 0. Received -1' | ||
| 158 | + } | ||
| 159 | + ); | ||
| 160 | + | ||
| 161 | + // Copy throws if sourceStart is greater than length of source | ||
| 162 | + assert.throws( | ||
| 163 | + () => Buffer.allocUnsafe(5).copy(Buffer.allocUnsafe(5), 0, 100), | ||
| 164 | + { | ||
| 165 | + code: 'ERR_OUT_OF_RANGE', | ||
| 166 | + name: 'RangeError', | ||
| 160 | 167 | } | |
| 161 | 168 | ); | |
| 162 | 169 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments