File tree Expand file tree Collapse file tree 1 file changed +20
-1
lines changed
packages/hoppscotch-common/src/helpers/import-export/import Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -147,6 +147,25 @@ const getHoppReqVariables = (
147147 }
148148}
149149
150+ // This regex is used to remove unsupported unicode characters from the response body which fails in Prisma
151+ // https://dba.stackexchange.com/questions/115029/unicode-error-with-u0000-on-copy-of-large-json-file-into-postgres
152+ const UNSUPPORTED_UNICODES_REGEX = / [ \u0000 ] / g
153+
154+ const getHoppResponseBody = (
155+ body : string | ArrayBuffer | undefined
156+ ) : string => {
157+ if ( ! body ) return ""
158+ if ( typeof body === "string" )
159+ return body . replace ( UNSUPPORTED_UNICODES_REGEX , "" )
160+ if ( body instanceof ArrayBuffer ) {
161+ return new TextDecoder ( )
162+ . decode ( body )
163+ . replace ( UNSUPPORTED_UNICODES_REGEX , "" )
164+ }
165+
166+ return ""
167+ }
168+
150169const getHoppResponses = (
151170 responses : Item [ "responses" ]
152171) : HoppRESTRequestResponses => {
@@ -157,7 +176,7 @@ const getHoppResponses = (
157176 const res = {
158177 name : response . name ,
159178 status : response . status ,
160- body : response . body ?? "" ,
179+ body : getHoppResponseBody ( response . body ) ,
161180 headers : getHoppReqHeaders ( response . headers ) ,
162181 code : response . code ,
163182 originalRequest : makeHoppRESTResponseOriginalRequest ( {
You can’t perform that action at this time.
0 commit comments