imcvampire / vue-truncate-filter

A filter for Vuejs to truncate string
MIT License
57 stars 6 forks source link

fails on null #10

Closed vexsolutions closed 6 years ago

vexsolutions commented 6 years ago

Would be great if it checked for null and just returned instead of throwing an error.

[Vue warn]: Error in render: "TypeError: Cannot read property 'length' of null"

imcvampire commented 6 years ago

Fixed in https://github.com/imcvampire/vue-truncate-filter/pull/11

AeonFr commented 5 years ago

I downloaded the repo recently from npm and the bug is still active. I realize the line 16 added in vue-truncate.js should prevent this:

    Vue.filter('truncate', function (text, length, clamp) {
      text = text || ''; // <= this line should prevent the error

Yet, looking at my local copy of vue-truncate.js (the one in my node_modules folder), I see that the line in question is not added. I think npm might have an old version of the repo, maybe?

Edit: It's also possible I just have a wrong configuration in my package.json, but I'm not sure how to check so I figured I might find more info here

imcvampire commented 5 years ago

What is your version of this package on your package.json?

AeonFr commented 5 years ago

I'm not currently on the same PC as before, but I did a quick test:

  1. Run npm install vue-truncate-filter on an empty folder
  2. Open node_modules/vue-truncate-filter/vue-truncate.js
  3. Line 16 is not there (the file is like in a previous commit)

That's why I've been digging into the package.json docs and found this:

The name and version together form an identifier that is assumed to be completely unique. Changes to the package should come along with changes to the version.

It seems like npm is not resolving to the latest version, even though package.json says it does.

For the record, this is exactly the content of package.json after my experiment:

{
  "requires": true,
  "lockfileVersion": 1,
  "dependencies": {
    "vue-truncate-filter": {
      "version": "1.1.7",
      "resolved": "https://registry.npmjs.org/vue-truncate-filter/-/vue-truncate-filter-1.1.7.tgz",
      "integrity": "sha512-kFmUDsDFIj5vArdK6hX84v80fTWJIMrsYF5keCluy9hMiaKGL8NyApnMbWavZeDod24YeYMVQ9jjd7MkRn3AAg=="
    }
  }
}

I think the problem might be that npm has stored "in cache" an old version. After the commit to fix this bug, the version in this repository's package.json should have been increased, ending up in 1.1.8 or something like that.

Changing this should make npm keep and distribute the latest version on the code 🙂

Thanks for publishing this repo and hope this helps ~