Skip to content

Commit

Permalink
fix: update url encoded form handling
Browse files Browse the repository at this point in the history
  • Loading branch information
vmlinz committed Feb 26, 2021
1 parent 91af5f1 commit 8c7abdc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions src/requestconf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
AxiosBasicCredentials,
AxiosProxyConfig,
} from 'axios';
import { getEscapeString, isObject, isURLSearchParams } from './util';
import { getEscapeString, isObject, isURLSearchParams, isString } from './util';

// builder for request config
const builder = {
Expand Down Expand Up @@ -107,15 +107,17 @@ if (config.data) {
}
}

core.info(`axios config: ${core.getInput('content-type')}`);
core.info(`axios config: ${core.getInput('content-type')}, ${JSON.stringify(config.data)}`);
if (core.getInput('content-type')) {
config.headers = {
...config.headers,
'Content-Type': core.getInput('content-type'),
};

if (core.getInput('content-type') === 'application/x-www-form-urlencoded') {
if (!isURLSearchParams(config.data) && isObject(config.data)) {
config.data = new URLSearchParams(config.data);
if (!isString(config.data)) {
const params = new URLSearchParams(config.data);
config.data = params.toString();
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,13 @@ export function isURLSearchParams(val: any) {
export function isObject(val: any) {
return val !== null && typeof val === 'object';
}

/**
* Determine if a value is a String
*
* @param {Object} val The value to test
* @returns {boolean} True if value is a String, otherwise false
*/
export function isString(val: any) {
return val !== null && typeof val === 'string';
}

0 comments on commit 8c7abdc

Please sign in to comment.