budiadiono / mongoose-slug-hero Goto Github PK
View Code? Open in Web Editor NEWMongoose trackable unique slug generator plugin
License: MIT License
Mongoose trackable unique slug generator plugin
License: MIT License
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.
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?
Can the history can be set to false?
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!
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.