Git Product home page Git Product logo

mongoose-slug-hero's People

Contributors

adionob avatar ardaogulcan avatar budiadiono avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

mongoose-slug-hero's Issues

Slug dependency vulnerability

This is not yet a huge issue, but the slug package that you are using for mongoose-slug-hero has not been maintained for the past 3 years.

Late May / early June a vulnerability has been discovered that allows for a ReDoS. I was wondering if you're exploring other options or would like some help getting this resolved through exploring alternatives?

Right now the options I've seen that would fix this issue would be alternatives like slugify or mollusc (active fork of this package) until this gets fixed. If requested, I can test either one of these packages and make a PR soon.

custom slugs?

I have two fields in my model (name and model) and i want my slug to be constructed on these 2 fields.
Is this even possible?

model fields being erased

Hi @budiadiono! Thank you for publishing this module.
It works as expected, except for an issue where when I try to update my model, my fields are being assigned 'null'.

Here's my workflow:
I create a new article, fill out all the fields, the slug is created correctly.
When I edit the article, the edit view loads the correct article, pre-populates the fields as expected.
When I submit the update request, all the fields are nullified EXCEPT the slug field.

I am not having this issue with other models where this extension is not being used. Am I missing something?

Here's my config:

var slugHero = require('mongoose-slug-hero'),
  mongoose = require('mongoose'),
  Schema = mongoose.Schema;

var articleSchema = new Schema({
  category                  : [{ type: Schema.Types.ObjectId, ref: 'Category' }],
  title                     : { type : String, required: true },
  intro                     : { type : String },
  body                      : { type: String},
  quote                     : { type: String},
  quote_citation    : { type: String},
  cover                     : { type: String },
  updated_at            : { type: Date, default: Date.now },
  published             : { type: Boolean }
});

articleSchema.plugin(slugHero, {doc: 'article', field: 'title'});

mongoose.model('Article', articleSchema);

here's my view:

{{#article}}
<h2>Edit Article</h2>

<form class="form" action="/articles/update/{{_id}}" method="post" enctype="multipart/form-data">

    <div class="row">
        <div class="col-md-6 form-group">
            <input name="title" type="text" class="form-control" value="{{title}}">
        </div>
        <div class="col-md-6 form-group">
            <select class="form-control" name="category">
                <option>TODO</option>
            </select>
        </div>                              
    </div>

    <div class="row">
        <div class="col-md-12 form-group">
            <input name="slug" value="{{slug}}" class="form-control" disabled></input>
        </div><!--/.col-md-12-->
    </div><!--/.row-->

    <div class="row">
        <div class="col-md-12 form-group">
            <input name="intro" class="form-control" value="{{intro}}"></input>
        </div><!--/.col-md-12-->
    </div><!--/.row-->


    <div class="row">
        <div class="col-md-12 form-group">
            <textarea name="body" val="" cols="30" rows="10" class="summernote form-control" value="{{body}}"></textarea>
        </div><!--/.col-md-12-->
    </div><!--/.row-->

    <div class="row">
        <div class="col-md-12 form-group">
            <input name="cover" type="file" class="form-control"/>
        </div><!--/.col-md-12-->
    </div><!--/.row-->

    <div class="row">
        <div class="col-md-12 form-group">
            <div class="checkbox">
              <label><input type="checkbox" name="published" value="" >Published</label>
            </div>
        </div>
    </div>

    <input type='submit' value='Edit' class="btn btn-primary"/> 
</form>
{{/article}}

And controller/route:

var mongoose = require('mongoose'),
  Article = mongoose.model('Article');
// ...
  update: function(req, res){
    Article.findOneAndUpdate({ _id: req.params.id }, {
      category        : req.body.category,
      title           : req.body.title,
      intro           : req.body.intro,
      body            : req.body.body,
      quote           : req.body.quote,
      quote_citation  : req.body.quote_citation,
      cover           : req.body.cover,
      published       : req.body.published }, function(err, article){
        if(err) res.render('error', { error: 'Error updating article'});
        res.redirect('/articles');
    });
  }
};

Thank you in advance!

"Cannot read property 'toString' of undefined" when using dot notation on "field" option

i'm getting an error when defining the slug field with "." notation, for instance field: 'info.title'

   TypeError: Uncaught error: Cannot read property 'toString' of undefined
  at slug (/Volumes/backpack/git/loopcast/killer/node_modules/slug/slug.js:13:20)
  at model.<anonymous> (/Volumes/backpack/git/loopcast/killer/node_modules/mongoose-slug-hero/lib/mongoose-slug-hero.js:105:10)
[...]

the problem comes from the fact that you check for the property with "_this[slugField]" which won't translate well in case there is a "." on the field.

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.