Do not try to request thumbnails with non-integer widths

Issue described in https://github.com/vector-im/riot-web/issues/9690.

With certain `window.devicePixelRatio` values
(e.g.  `1.5789473684210527`), the calculated thumb width/height
would be a non-integer value.

Passing such values to `client.mxcUrlToHttp()` causes it to
generate URLs to the thumbnail API with non-integer values.
As per the spec, non-integer values are forbidden for that API and a
400 HTTP response is returned (`Query parameter b'width' must be an
integer`).

Fixing matrix-js-sdk's `mxcUrlToHttp()` to sanitize such values
would also be a good idea and likely fix more than just matrix-react-sdk
and riot-web. Still, it feels like matrix-react-sdk should play nice
as well, and not request thumbnails for weird widths/heights.

Signed-off-by: Slavi Pantaleev <slavi@devture.com>
pull/21833/head
Slavi Pantaleev 2019-05-27 11:06:10 +03:00
parent c30908c380
commit 3f60b4336f
1 changed files with 2 additions and 2 deletions

View File

@ -172,8 +172,8 @@ export default class MImageBody extends React.Component {
// thumbnail resolution will be unnecessarily reduced.
// custom timeline widths seems preferable.
const pixelRatio = window.devicePixelRatio;
const thumbWidth = 800 * pixelRatio;
const thumbHeight = 600 * pixelRatio;
const thumbWidth = Math.round(800 * pixelRatio);
const thumbHeight = Math.round(600 * pixelRatio);
const content = this.props.mxEvent.getContent();
if (content.file !== undefined) {