Giter Site home page Giter Site logo

Comments (5)

sidorares avatar sidorares commented on June 1, 2024 1

@aaron13100 do you want to send a PR with added null, 0?

from node-mysql2.

wellwelwel avatar wellwelwel commented on June 1, 2024

Edited


This happens when you change the native JSON.stringify method:

// It's a string
return ((function () {
  return class TextRow {
    constructor(fields) {
    }
    next(packet, fields, options) {
      this.packet = packet;
      const result = {};
      //
      "version()": : VAR_STRING
      result[
        "version()": ] = packet.readLengthCodedString(fields[0].encoding);
        return result;
      }
    };
  })())

Look at that:

//
"version()": : VAR_STRING

Now, what it should be:

// It's a string
return ((function () {
  return class TextRow {
    constructor(fields) {
    }
    next(packet, fields, options) {
      this.packet = packet;
      const result = {};
      // "version()": VAR_STRING
      result["version()"] = packet.readLengthCodedString(fields[0].encoding);
      return result;
    }
  };
})())

from node-mysql2.

wellwelwel avatar wellwelwel commented on June 1, 2024

Since this error comes from an external dependency, I will close this issue as not planned.
But feel free to ask anything and reopen it at anytime 🙋🏻‍♂️

from node-mysql2.

sidorares avatar sidorares commented on June 1, 2024

the error actually comes from srcEscape, here is smaller self contained example:

const originalStringify = JSON.stringify;

if (true) {
/* without this override there is no error */
  JSON.stringify = function (obj, replacer = null, space = 2) {
    return originalStringify(obj, replacer, space);
  };
}


function srcEscape(str) {
    return JSON.stringify({
      [str]: 1
    }).slice(1, -3);
}

console.log(srcEscape(`test("test")`));

we can probably change to something more reliable:

    return JSON.stringify({
      [str]: 1
    }).trim().slice(1, -1).split('\n').filter(s => s.length > 0).split(':').slice(0, -1).join('')

or just use some more simple way of escaping. JSON.stringify + key extract works both fast and reliable but I'm open to other suggestions.

Another fix that would work with @aaron13100 example is to just pass replacer and space explicitly in srcEscape:

function srcEscape(str) {
    return JSON.stringify({
      [str]: 1
    }, null, 0).slice(1, -3);
}

from node-mysql2.

wellwelwel avatar wellwelwel commented on June 1, 2024

Thanks, @sidorares 🙋🏻‍♂️

I've adjusted my comment.

from node-mysql2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.