Skip to content

Commit

Permalink
safely decode data index
Browse files Browse the repository at this point in the history
  • Loading branch information
ferronrsmith committed Nov 9, 2023
1 parent 7c4fb60 commit f2d34f0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/transports/__es__/_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const jsonParser = require('../../jsonparser.js')
const aws4signer = require('../../aws4signer')
const { parseMetaFields } = require('../../parse-meta-data')
const _ = require('lodash')
const { scrollResultSet } = require('./_helpers')
const { scrollResultSet, safeDecodeURIComponent } = require('./_helpers')

class Data {
async getData (limit, offset, callback) {
Expand Down Expand Up @@ -124,7 +124,7 @@ class Data {
const actionMeta = { [bulkAction]: {} }

// use index from base otherwise fallback to elem
actionMeta[bulkAction]._index = this.base.index || elem._index
actionMeta[bulkAction]._index = safeDecodeURIComponent(this.base.index) || elem._index

// https://www.elastic.co/guide/en/elasticsearch/reference/master/removal-of-types.html
if (this.ESversion < 7) {
Expand Down
11 changes: 10 additions & 1 deletion lib/transports/__es__/_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,15 @@ const scrollResultSet = (self, callback, loadedHits, response) => {
}
}

const safeDecodeURIComponent = (uri) => {
try {
return decodeURIComponent(uri)
} catch (_) {
return uri
}
}

module.exports = {
scrollResultSet
scrollResultSet,
safeDecodeURIComponent
}

0 comments on commit f2d34f0

Please sign in to comment.