Skip to content

Commit 6fdf40a

Browse files
committed
fix #327 again
1 parent a930ecf commit 6fdf40a

File tree

6 files changed

+37
-672
lines changed

6 files changed

+37
-672
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 1.10.1
4+
5+
* fix another encoding issue, fixes again [#327](https://github.com/cars10/elasticvue/issues/327)
6+
37
## 1.10.0
48

59
* fix encoding issue in rest query interface, fixes [#327](https://github.com/cars10/elasticvue/issues/327)

src/composables/components/rest/RestQueryForm.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { fetchMethod } from '../../../helpers/fetch'
99
import { IdbRestQueryTab, IdbRestQueryTabRequest } from '../../../db/types.ts'
1010
import { debounce } from '../../../helpers/debounce.ts'
1111
import { parseKibana } from '../../../helpers/parseKibana.ts'
12-
import { cleanRestPath } from '../../../helpers/cleanRestPath.ts'
12+
import { cleanIndexName } from '../../../helpers/cleanIndexName.ts'
1313

1414
type RestQueryFormProps = {
1515
tab: IdbRestQueryTab
@@ -48,7 +48,7 @@ export const useRestQueryForm = (props: RestQueryFormProps, emit: any) => {
4848

4949
let url = connectionStore.activeCluster.uri
5050
if (!url.endsWith('/') && !props.tab.request.path.startsWith('/')) url += '/'
51-
url += cleanRestPath(props.tab.request.path)
51+
url += cleanIndexName(props.tab.request.path)
5252

5353
try {
5454
const fetchResponse = await fetchMethod(url, options)

src/helpers/cleanIndexName.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
export const cleanIndexName = (index: string) => {
2-
return index.replace(/%/g, '%25').replace(/<.*?>/g, (match) => {
3-
return match
2+
// First encode % characters that are NOT part of URL-encoded sequences
3+
// URL-encoded sequences are % followed by exactly 2 hex digits
4+
let result = index.replace(/%(?![\dA-Fa-f]{2})/g, '%25')
5+
6+
// Then encode characters only within datemath expressions (<...>)
7+
result = result.replace(/<([^>]*)>/g, (_, content) => {
8+
const encodedContent = content
49
.replace(/</g, '%3C')
510
.replace(/>/g, '%3E')
611
.replace(/\//g, '%2F')
@@ -10,5 +15,8 @@ export const cleanIndexName = (index: string) => {
1015
.replace(/\+/g, '%2B')
1116
.replace(/:/g, '%3A')
1217
.replace(/,/g, '%2C')
18+
return `%3C${encodedContent}%3E`
1319
})
20+
21+
return result
1422
}

src/helpers/cleanRestPath.ts

Lines changed: 0 additions & 155 deletions
This file was deleted.

tests/unit/helpers/cleanIndexName.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,25 @@ describe.concurrent('helpers/cleanIndexName.ts', () => {
3636
const cleanedName = 'movies/kube+foo/bar'
3737
expect(cleanIndexName(indexName)).toBe(cleanedName)
3838
})
39+
40+
it('should not double-encode already URL-encoded characters', () => {
41+
const testCases = [
42+
{
43+
input: 'my-index/_doc/my%2Fdocument%2Fid',
44+
expected: 'my-index/_doc/my%2Fdocument%2Fid'
45+
},
46+
{
47+
input: 'my-index-<{now/d}>/_doc/my%2Fdocument%2Fid',
48+
expected: 'my-index-%3C%7Bnow%2Fd%7D%3E/_doc/my%2Fdocument%2Fid'
49+
},
50+
{
51+
input: '_cluster/health',
52+
expected: '_cluster/health'
53+
}
54+
]
55+
56+
testCases.forEach(({ input, expected }) => {
57+
expect(cleanIndexName(input)).toBe(expected)
58+
})
59+
})
3960
})

0 commit comments

Comments
 (0)