mirror of
https://github.com/Kong/insomnia
synced 2024-11-08 06:39:48 +00:00
Render webviews in UTF-8 (#5836)
This commit is contained in:
parent
707822e691
commit
55b5260aa4
@ -1,5 +1,6 @@
|
||||
import { beforeEach, describe, expect, it, jest } from '@jest/globals';
|
||||
import { render } from '@testing-library/react';
|
||||
import iconv from 'iconv-lite';
|
||||
import React from 'react';
|
||||
import configureMockStore from 'redux-mock-store';
|
||||
import thunk from 'redux-thunk';
|
||||
@ -86,4 +87,18 @@ describe('<ResponseViewer />', () => {
|
||||
expect(responseWebView).toBeInTheDocument();
|
||||
expect(mockRenderWithProps).not.toHaveBeenCalledWith();
|
||||
});
|
||||
|
||||
it('should decode ISO-8859-1 HTML content and render encoded in UTF-8', async () => {
|
||||
const TEST_STRING = 'Viel Glück';
|
||||
const responseWebView = await getResponseViewerChild({
|
||||
contentType: 'text/html; charset=iso-8859-1',
|
||||
getBody: () => Buffer.from(iconv.encode(TEST_STRING, 'iso-8859-1')),
|
||||
}, 'ResponseWebView');
|
||||
|
||||
Object.assign(responseWebView, { loadURL: (url: string) => {
|
||||
expect(url).toEqual(`data:text/html; charset=utf-8,${encodeURIComponent(TEST_STRING)}`);
|
||||
} });
|
||||
|
||||
responseWebView.dispatchEvent(new Event('dom-ready'));
|
||||
});
|
||||
});
|
||||
|
@ -253,7 +253,6 @@ export const ResponseViewer = ({
|
||||
return (
|
||||
<ResponseWebView
|
||||
body={getBodyAsString()}
|
||||
contentType={contentType}
|
||||
key={disableHtmlPreviewJs ? 'no-js' : 'yes-js'}
|
||||
url={url}
|
||||
webpreferences={`disableDialogs=true, javascript=${disableHtmlPreviewJs ? 'no' : 'yes'
|
||||
|
@ -2,11 +2,10 @@ import React, { FC, useEffect, useRef } from 'react';
|
||||
|
||||
interface Props {
|
||||
body: string;
|
||||
contentType: string;
|
||||
url: string;
|
||||
webpreferences: string;
|
||||
}
|
||||
export const ResponseWebView: FC<Props> = ({ webpreferences, body, contentType, url }) => {
|
||||
export const ResponseWebView: FC<Props> = ({ webpreferences, body, url }) => {
|
||||
const webviewRef = useRef<Electron.WebviewTag>(null);
|
||||
|
||||
useEffect(() => {
|
||||
@ -15,7 +14,7 @@ export const ResponseWebView: FC<Props> = ({ webpreferences, body, contentType,
|
||||
if (webview) {
|
||||
webview.removeEventListener('dom-ready', handleDOMReady);
|
||||
const bodyWithBase = body.replace('<head>', `<head><base href="${url}">`);
|
||||
webview.loadURL(`data:${contentType},${encodeURIComponent(bodyWithBase)}`);
|
||||
webview.loadURL(`data:text/html; charset=utf-8,${encodeURIComponent(bodyWithBase)}`);
|
||||
}
|
||||
};
|
||||
if (webview) {
|
||||
@ -26,7 +25,7 @@ export const ResponseWebView: FC<Props> = ({ webpreferences, body, contentType,
|
||||
webview.removeEventListener('dom-ready', handleDOMReady);
|
||||
}
|
||||
};
|
||||
}, [body, contentType, url]);
|
||||
}, [body, url]);
|
||||
return (
|
||||
<webview
|
||||
data-testid="ResponseWebView"
|
||||
|
Loading…
Reference in New Issue
Block a user