mirror of
https://github.com/fjogeleit/http-request-action.git
synced 2026-02-04 16:45:52 +08:00
Support for unescaped newlines in data (#16)
* support newline escaping
This commit is contained in:
13
dist/index.js
vendored
13
dist/index.js
vendored
@@ -1023,10 +1023,16 @@ const axios = __webpack_require__(53);
|
||||
const METHOD_GET = 'GET'
|
||||
const METHOD_POST = 'POST'
|
||||
|
||||
const request = async({ method, instanceConfig, data, auth, actions, preventFailureOnNoResponse }) => {
|
||||
const request = async({ method, instanceConfig, data, auth, actions, preventFailureOnNoResponse, escapeData }) => {
|
||||
try {
|
||||
const instance = axios.create(instanceConfig);
|
||||
|
||||
if (escapeData) {
|
||||
data = data.replace(/"[^"]*"/g, (match) => {
|
||||
return match.replace(/[\n\r]\s*/g, "\\n");
|
||||
});
|
||||
}
|
||||
|
||||
const jsonData = method === METHOD_GET ? undefined : JSON.parse(data)
|
||||
|
||||
const requestData = {
|
||||
@@ -1052,7 +1058,7 @@ const request = async({ method, instanceConfig, data, auth, actions, preventFail
|
||||
} else if (error.request && preventFailureOnNoResponse) {
|
||||
actions.warning(JSON.stringify(error));
|
||||
} else {
|
||||
actions.setFailed(error.message);
|
||||
actions.setFailed(JSON.stringify({ message: error.message, data }));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2612,8 +2618,9 @@ core.debug('Instance Configuration: ' + JSON.stringify(instanceConfig))
|
||||
const data = core.getInput('data') || '{}';
|
||||
const method = core.getInput('method') || METHOD_POST;
|
||||
const preventFailureOnNoResponse = core.getInput('preventFailureOnNoResponse') === 'true';
|
||||
const escapeData = core.getInput('escapeData') === 'true';
|
||||
|
||||
request({ data, method, instanceConfig, auth, preventFailureOnNoResponse, actions: new GithubActions() })
|
||||
request({ data, method, instanceConfig, auth, preventFailureOnNoResponse, escapeData, actions: new GithubActions() })
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
Reference in New Issue
Block a user