hildjj / node-cbor

Encode and decode CBOR documents, with both easy mode, streaming mode, and SAX-style evented mode.
MIT License
356 stars 73 forks source link

Fix Buffer converter matcher being mangled in minimised builds #165

Closed noway closed 2 years ago

noway commented 2 years ago

Hi! šŸ‘‹

Firstly, thanks for your work on this project! šŸ™‚

Today I used patch-package to patch cbor@8.1.0 for the project I'm working on.

Fixes #164

Here is the diff that solved my problem:

diff --git a/node_modules/cbor/lib/encoder.js b/node_modules/cbor/lib/encoder.js
index 6327959..288c692 100644
--- a/node_modules/cbor/lib/encoder.js
+++ b/node_modules/cbor/lib/encoder.js
@@ -509,6 +509,9 @@ Call removeLoopDetectors before resuming.`)
       if (typeof f === 'function') {
         return f.call(obj, this)
       }
+      if (Buffer.isBuffer(obj)) {
+        return this.semanticTypes[Buffer.name].call(obj, this, obj)
+      }
       const converter = this.semanticTypes[obj.constructor.name]
       if (converter) {
         return converter.call(obj, this, obj)

This issue body was partially generated by patch-package.

noway commented 2 years ago

Sorry, thought this going to open a PR, opened a proper PR instead in #166