hbsig 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cjs/httpsig.js CHANGED
@@ -414,14 +414,12 @@ function parseMultipart(contentType, body) {
414
414
  var name = line.substring(0, colonIndex).toLowerCase();
415
415
  var value = line.substring(colonIndex + 2);
416
416
 
417
- // Special handling for known binary fields or detected binary data
418
- if (name === "owner" || name === "signature") {
419
- // These fields contain binary data that may have embedded newlines
420
- // We need to read until we find the next header or end of headers
417
+ // Check if this might be binary data by looking at the first part
418
+ var valueBuf = Buffer.from(value, "binary");
419
+ var mightBeBinary = isBinaryData(valueBuf);
420
+ if (mightBeBinary) {
421
+ // Binary data may contain embedded newlines, so read until next header
421
422
  var valueStart = currentPos + colonIndex + 2;
422
-
423
- // Look ahead to find where this field really ends
424
- // The next header will start with a valid header name followed by ": "
425
423
  var searchPos = valueStart;
426
424
  var valueEnd = headerBlock.length;
427
425
 
@@ -429,40 +427,24 @@ function parseMultipart(contentType, body) {
429
427
  while (searchPos < headerBlock.length) {
430
428
  var nextNewline = headerBlock.indexOf("\n", searchPos);
431
429
  if (nextNewline === -1) break;
432
-
433
- // Check if what follows looks like a header
434
430
  var nextLineStart = nextNewline + 1;
435
431
  var nextColon = headerBlock.indexOf(":", nextLineStart);
436
-
437
- // Valid header should have colon relatively close to line start
438
432
  if (nextColon > nextLineStart && nextColon < nextLineStart + 50) {
439
- // Check if the text before colon looks like a header name (ASCII text)
440
433
  var possibleHeaderName = headerBlock.substring(nextLineStart, nextColon);
441
434
  var looksLikeHeader = /^[a-zA-Z0-9-]+$/.test(possibleHeaderName);
442
435
  if (looksLikeHeader) {
443
- // Found the next header, value ends at the newline before it
444
436
  valueEnd = nextNewline;
445
437
  break;
446
438
  }
447
439
  }
448
440
  searchPos = nextNewline + 1;
449
441
  }
450
-
451
- // Extract the full value as binary string
452
442
  value = headerBlock.substring(valueStart, valueEnd);
453
-
454
- // Remove trailing CR if present (since we found the LF)
455
443
  if (value.endsWith("\r")) {
456
444
  value = value.substring(0, value.length - 1);
457
445
  }
458
-
459
- // Convert to Buffer to preserve binary
460
446
  headers[name] = Buffer.from(value, "binary");
461
447
  currentPos = valueEnd + 1;
462
- } else if (isBinaryData(Buffer.from(value, "binary"))) {
463
- // Regular field but contains binary data
464
- headers[name] = Buffer.from(value, "binary");
465
- currentPos = lineEnd + (headerBlock[lineEnd] === "\r" ? 2 : 1);
466
448
  } else {
467
449
  // Regular text field
468
450
  headers[name] = value;
package/esm/httpsig.js CHANGED
@@ -360,14 +360,13 @@ function parseMultipart(contentType, body) {
360
360
  const name = line.substring(0, colonIndex).toLowerCase()
361
361
  let value = line.substring(colonIndex + 2)
362
362
 
363
- // Special handling for known binary fields or detected binary data
364
- if (name === "owner" || name === "signature") {
365
- // These fields contain binary data that may have embedded newlines
366
- // We need to read until we find the next header or end of headers
367
- let valueStart = currentPos + colonIndex + 2
363
+ // Check if this might be binary data by looking at the first part
364
+ const valueBuf = Buffer.from(value, "binary")
365
+ const mightBeBinary = isBinaryData(valueBuf)
368
366
 
369
- // Look ahead to find where this field really ends
370
- // The next header will start with a valid header name followed by ": "
367
+ if (mightBeBinary) {
368
+ // Binary data may contain embedded newlines, so read until next header
369
+ let valueStart = currentPos + colonIndex + 2
371
370
  let searchPos = valueStart
372
371
  let valueEnd = headerBlock.length
373
372
 
@@ -376,13 +375,10 @@ function parseMultipart(contentType, body) {
376
375
  let nextNewline = headerBlock.indexOf("\n", searchPos)
377
376
  if (nextNewline === -1) break
378
377
 
379
- // Check if what follows looks like a header
380
378
  let nextLineStart = nextNewline + 1
381
379
  let nextColon = headerBlock.indexOf(":", nextLineStart)
382
380
 
383
- // Valid header should have colon relatively close to line start
384
381
  if (nextColon > nextLineStart && nextColon < nextLineStart + 50) {
385
- // Check if the text before colon looks like a header name (ASCII text)
386
382
  let possibleHeaderName = headerBlock.substring(
387
383
  nextLineStart,
388
384
  nextColon
@@ -390,7 +386,6 @@ function parseMultipart(contentType, body) {
390
386
  let looksLikeHeader = /^[a-zA-Z0-9-]+$/.test(possibleHeaderName)
391
387
 
392
388
  if (looksLikeHeader) {
393
- // Found the next header, value ends at the newline before it
394
389
  valueEnd = nextNewline
395
390
  break
396
391
  }
@@ -398,21 +393,13 @@ function parseMultipart(contentType, body) {
398
393
  searchPos = nextNewline + 1
399
394
  }
400
395
 
401
- // Extract the full value as binary string
402
396
  value = headerBlock.substring(valueStart, valueEnd)
403
-
404
- // Remove trailing CR if present (since we found the LF)
405
397
  if (value.endsWith("\r")) {
406
398
  value = value.substring(0, value.length - 1)
407
399
  }
408
400
 
409
- // Convert to Buffer to preserve binary
410
401
  headers[name] = Buffer.from(value, "binary")
411
402
  currentPos = valueEnd + 1
412
- } else if (isBinaryData(Buffer.from(value, "binary"))) {
413
- // Regular field but contains binary data
414
- headers[name] = Buffer.from(value, "binary")
415
- currentPos = lineEnd + (headerBlock[lineEnd] === "\r" ? 2 : 1)
416
403
  } else {
417
404
  // Regular text field
418
405
  headers[name] = value
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hbsig",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "main": "cjs/index.js",
5
5
  "license": "MIT",
6
6
  "devDependencies": {