Skip to content

Commit 77aa3a8

Browse files
RatGabiSethKkiskozadependabot[bot]hemanth-3
authored
Ensured resolveHost is idempotent (#531)
* Updated picker version v1.24.0 * Updated realease version and changelog * Bump fast-xml-parser (#521) * build(deps): bump fast-xml-parser from 3.16.0 to 4.2.4 Bumps [fast-xml-parser](https://github.com/NaturalIntelligence/fast-xml-parser) from 3.16.0 to 4.2.4. - [Release notes](https://github.com/NaturalIntelligence/fast-xml-parser/releases) - [Changelog](https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/CHANGELOG.md) - [Commits](https://github.com/NaturalIntelligence/fast-xml-parser/commits) --- updated-dependencies: - dependency-name: fast-xml-parser dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> * Fix code after fast-xml-parser version bump --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Updated Changelog and version * Ensured resolveHost is idempotent --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: SethK <seth.k@filetstack.com> Co-authored-by: Zsolt Kozaroczy <kiskoza@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: hemanth-3 <98961835+hemanth-3@users.noreply.github.com>
1 parent 4be7b71 commit 77aa3a8

File tree

7 files changed

+48
-10
lines changed

7 files changed

+48
-10
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5+
## [3.27.0](https://github.com/filestack/filestack-js/compare/v3.26.1...v3.27.0) (2023-08-07)
6+
7+
### Fix
8+
* **fast-xml-parser:** It's a security upgrade based on ([#518](https://github.com/filestack/filestack-js/issues/518)) . Dependabot did the version bump and then fixed the tests([#521](https://github.com/filestack/filestack-js/pull/521)).
9+
10+
## [3.26.1](https://github.com/filestack/filestack-js/compare/v3.26.0...v3.26.1) (2023-04-06)
11+
12+
### Fix
13+
* **picker:** Fixed console error during file select and upload
14+
15+
## [3.26.0](https://github.com/filestack/filestack-js/compare/v3.25.0...v3.26.0) (2023-03-30)
16+
### Feature
17+
* **picker:** Added possibility to predefine the results for the imagesearch in Picker
18+
* **picker:** Picker - Display Unsplash Search and Good Old Image Search as two tabs of one "source"
19+
520
## [3.25.0](https://github.com/filestack/filestack-js/compare/v3.24.1...v3.25.0) (2021-10-05)
621

722

package-lock.json

Lines changed: 12 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "filestack-js",
3-
"version": "3.25.0",
3+
"version": "3.27.0",
44
"description": "Official JavaScript library for Filestack",
55
"main": "build/main/index.js",
66
"module": "build/module/index.js",
@@ -45,7 +45,7 @@
4545
"abab": "^2.0.3",
4646
"debug": "^4.1.1",
4747
"eventemitter3": "^4.0.0",
48-
"fast-xml-parser": "^3.16.0",
48+
"fast-xml-parser": "^4.2.4",
4949
"file-type": "^10.11.0",
5050
"follow-redirects": "^1.10.0",
5151
"isutf8": "^2.1.0",

src/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
/**
1919
* @private
2020
*/
21+
2122
const PICKER_VERSION = 'beta';
2223

2324
/**

src/lib/request/helpers/data.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { isURLSearchParams, isObject, isStream, isFormData, isArrayBuffer, isFil
1818
import { getVersion, uniqueId } from './../../utils';
1919
import { FsRequestOptions, FsResponse } from './../types';
2020
import { set } from './headers';
21-
import * as parser from 'fast-xml-parser';
21+
import { XMLParser, XMLValidator } from 'fast-xml-parser';
2222
import Debug from 'debug';
2323

2424
const debug = Debug('fs:request:data');
@@ -99,11 +99,14 @@ export const parseResponse = async (response: FsResponse): Promise<FsResponse> =
9999
data = bufferToString(response.data);
100100
}
101101

102-
if (parser.validate(data) === true) {
103-
response.data = parser.parse(data, {
102+
if (XMLValidator.validate(data) === true) {
103+
const parser = new XMLParser({
104+
ignoreDeclaration: true,
104105
ignoreAttributes : true,
105106
trimValues: true,
106107
});
108+
109+
response.data = parser.parse(data);
107110
}
108111
}
109112

src/lib/utils/index.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,15 @@ describe('utils:index', () => {
7272
const result = resolveHost(hosts, cname);
7373
checkHosts(result, cname);
7474
});
75+
76+
it('should be idempotent', () => {
77+
const cname = 'stage.filestackapi.com';
78+
const firstResult = resolveHost(hosts, cname);
79+
const copiedResult = JSON.parse(JSON.stringify(firstResult));
80+
const secondResult = resolveHost(copiedResult, cname);
81+
82+
expect(JSON.stringify(firstResult)).toEqual(JSON.stringify(secondResult));
83+
});
7584
});
7685

7786
describe('removeEmpty', () => {

src/lib/utils/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ export const resolveHost = (urls: Hosts, cname: string): Hosts => {
5858
const hosts = /filestackapi.com|filestackcontent.com/i;
5959

6060
Object.keys(urls).forEach(key => {
61-
urls[key] = urls[key].replace(hosts, cname);
61+
if (!new RegExp(cname, 'i').test(urls[key])) {
62+
urls[key] = urls[key].replace(hosts, cname);
63+
}
6264
});
6365

6466
return urls;

0 commit comments

Comments
 (0)