mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-19 04:17:44 +00:00
escape json special chars in metadata (#1399)
This commit is contained in:
@@ -5,6 +5,17 @@ const moment = require('moment');
|
||||
const MAX_PLAY_AUDIO_QUEUE_SIZE = 10;
|
||||
const DTMF_SPAN_NAME = 'dtmf';
|
||||
|
||||
function escapeString(str) {
|
||||
return str
|
||||
.replace(/\\/g, '\\\\') // Escape backslashes
|
||||
.replace(/"/g, '\\"') // Escape double quotes
|
||||
.replace(/\b/g, '\\b') // Escape backspace
|
||||
.replace(/\f/g, '\\f') // Escape formfeed
|
||||
.replace(/\n/g, '\\n') // Escape newlines
|
||||
.replace(/\r/g, '\\r') // Escape carriage returns
|
||||
.replace(/\t/g, '\\t'); // Escape tabs
|
||||
}
|
||||
|
||||
class TaskListen extends Task {
|
||||
constructor(logger, opts, parentTask) {
|
||||
super(logger, opts);
|
||||
@@ -16,10 +27,20 @@ class TaskListen extends Task {
|
||||
this.preconditions = TaskPreconditions.Endpoint;
|
||||
|
||||
[
|
||||
'action', 'auth', 'method', 'url', 'finishOnKey', 'maxLength', 'metadata', 'mixType', 'passDtmf', 'playBeep',
|
||||
'action', 'auth', 'method', 'url', 'finishOnKey', 'maxLength', 'mixType', 'passDtmf', 'playBeep',
|
||||
'sampleRate', 'timeout', 'transcribe', 'wsAuth', 'disableBidirectionalAudio', 'channel'
|
||||
].forEach((k) => this[k] = this.data[k]);
|
||||
|
||||
//Escape JSON special characters in metadata
|
||||
if (this.data.metadata) {
|
||||
this.metadata = {};
|
||||
for (const key in this.data.metadata) {
|
||||
if (this.data.metadata.hasOwnProperty(key)) {
|
||||
this.metadata[key] = escapeString(this.data.metadata[key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.mixType = this.mixType || 'mono';
|
||||
this.sampleRate = this.sampleRate || 8000;
|
||||
this.earlyMedia = this.data.earlyMedia === true;
|
||||
|
||||
Reference in New Issue
Block a user