Skip to content

Commit

Permalink
Ensured resolveHost is idempotent (#531)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
5 people authored Sep 29, 2023
1 parent 4be7b71 commit 77aa3a8
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 10 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@

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.

## [3.27.0](https://github.com/filestack/filestack-js/compare/v3.26.1...v3.27.0) (2023-08-07)

### Fix
* **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)).

## [3.26.1](https://github.com/filestack/filestack-js/compare/v3.26.0...v3.26.1) (2023-04-06)

### Fix
* **picker:** Fixed console error during file select and upload

## [3.26.0](https://github.com/filestack/filestack-js/compare/v3.25.0...v3.26.0) (2023-03-30)
### Feature
* **picker:** Added possibility to predefine the results for the imagesearch in Picker
* **picker:** Picker - Display Unsplash Search and Good Old Image Search as two tabs of one "source"

## [3.25.0](https://github.com/filestack/filestack-js/compare/v3.24.1...v3.25.0) (2021-10-05)


Expand Down
16 changes: 12 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "filestack-js",
"version": "3.25.0",
"version": "3.27.0",
"description": "Official JavaScript library for Filestack",
"main": "build/main/index.js",
"module": "build/module/index.js",
Expand Down Expand Up @@ -45,7 +45,7 @@
"abab": "^2.0.3",
"debug": "^4.1.1",
"eventemitter3": "^4.0.0",
"fast-xml-parser": "^3.16.0",
"fast-xml-parser": "^4.2.4",
"file-type": "^10.11.0",
"follow-redirects": "^1.10.0",
"isutf8": "^2.1.0",
Expand Down
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
/**
* @private
*/

const PICKER_VERSION = 'beta';

/**
Expand Down
9 changes: 6 additions & 3 deletions src/lib/request/helpers/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { isURLSearchParams, isObject, isStream, isFormData, isArrayBuffer, isFil
import { getVersion, uniqueId } from './../../utils';
import { FsRequestOptions, FsResponse } from './../types';
import { set } from './headers';
import * as parser from 'fast-xml-parser';
import { XMLParser, XMLValidator } from 'fast-xml-parser';
import Debug from 'debug';

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

if (parser.validate(data) === true) {
response.data = parser.parse(data, {
if (XMLValidator.validate(data) === true) {
const parser = new XMLParser({
ignoreDeclaration: true,
ignoreAttributes : true,
trimValues: true,
});

response.data = parser.parse(data);
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/lib/utils/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ describe('utils:index', () => {
const result = resolveHost(hosts, cname);
checkHosts(result, cname);
});

it('should be idempotent', () => {
const cname = 'stage.filestackapi.com';
const firstResult = resolveHost(hosts, cname);
const copiedResult = JSON.parse(JSON.stringify(firstResult));
const secondResult = resolveHost(copiedResult, cname);

expect(JSON.stringify(firstResult)).toEqual(JSON.stringify(secondResult));
});
});

describe('removeEmpty', () => {
Expand Down
4 changes: 3 additions & 1 deletion src/lib/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ export const resolveHost = (urls: Hosts, cname: string): Hosts => {
const hosts = /filestackapi.com|filestackcontent.com/i;

Object.keys(urls).forEach(key => {
urls[key] = urls[key].replace(hosts, cname);
if (!new RegExp(cname, 'i').test(urls[key])) {
urls[key] = urls[key].replace(hosts, cname);
}
});

return urls;
Expand Down

0 comments on commit 77aa3a8

Please sign in to comment.