Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue where upper case tags in the get helper fails in case sensitive db #9819

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions core/server/models/plugins/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,18 @@ filter = function filter(Bookshelf) {
},

preProcessFilters: function preProcessFilters() {
/* Lowercase filters for tags and slug no matter how they are passed in */
this._filters.statements = gql.json.replaceStatements(this._filters.statements, {prop: /tags|slug/}, function (statement) {

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the rebase ☹️We replaced GQL and had to refactor the filter plugin.
Let me know if you need a hand, i can help 👍

if (Array.isArray(statement.value)) {
statement.value = statement.value.map(function mapValue(value) {
return value.toLowerCase();
});
} else {
statement.value = statement.value.toLowerCase();
}
return statement;
});

this._filters.statements = gql.json.replaceStatements(this._filters.statements, {prop: /primary_tag/}, function (statement) {
statement.prop = 'tags.slug';
return {
Expand Down
59 changes: 58 additions & 1 deletion core/test/unit/models/plugins/filter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,64 @@ describe('Filter', function () {
});

describe('Pre Process Filters', function () {
it('should not have tests yet, as this needs to be removed');
it('should lower case slug filter', function () {
ghostBookshelf.Model.prototype._filters = {
statements: [
{prop: 'slug', op: '=', value: 'TEST-123'}
]
};
ghostBookshelf.Model.prototype.preProcessFilters();
ghostBookshelf.Model.prototype._filters.statements[0]
.value.should.be.exactly('test-123');
});

it('should lower case tags filter', function () {
ghostBookshelf.Model.prototype._filters = {
statements: [
{prop: 'tags', op: '=', value: 'TEST-123'}
]
};
ghostBookshelf.Model.prototype.preProcessFilters();
ghostBookshelf.Model.prototype._filters.statements[0]
.value.should.be.exactly('test-123');
});

it('should not lower case other filter', function () {
ghostBookshelf.Model.prototype._filters = {
statements: [
{prop: 'title', op: '=', value: 'TEST-123'}
]
};
ghostBookshelf.Model.prototype.preProcessFilters();
ghostBookshelf.Model.prototype._filters.statements[0]
.value.should.be.exactly('TEST-123');
});

it('should lower case tags array filter', function () {
ghostBookshelf.Model.prototype._filters = {
statements: [
{prop: 'tags', op: '=', value: ['TEST-123', 'TEST-456']}
]
};
ghostBookshelf.Model.prototype.preProcessFilters();
ghostBookshelf.Model.prototype._filters.statements[0]
.value[0].should.be.exactly('test-123');
ghostBookshelf.Model.prototype._filters.statements[0]
.value[1].should.be.exactly('test-456');
});

it('should lower case tags filter inside groups', function () {
ghostBookshelf.Model.prototype._filters = {
statements: [{
group: [
{prop: 'tags', op: '=', value: 'TEST-123'}
]
}]
};
ghostBookshelf.Model.prototype.preProcessFilters();
ghostBookshelf.Model.prototype._filters.statements[0]
.group[0].value.should.be.exactly('test-123');
});
});

describe('Post Process Filters', function () {
Expand Down