这是indexloc提供的服务,不要输入任何密码
Skip to content

Commit 4dc35be

Browse files
daehlilaurentlp
andauthored
fix(builtin_image): Modified how we search for Minetype in the image component. (#5401)
* We are always receiving URL. Some URL are passe with all the search query. The Path.extname method didn't return the good format. Some image was not able to rendered. * Catch error for the URL * Update modules/channel-web/src/views/lite/components/messages/renderer/FileMessage.tsx Co-authored-by: Laurent Leclerc Poulin <laurentlp@users.noreply.github.com> Co-authored-by: Laurent Leclerc Poulin <laurentlp@users.noreply.github.com>
1 parent f6632ba commit 4dc35be

File tree

1 file changed

+10
-2
lines changed
  • modules/channel-web/src/views/lite/components/messages/renderer

1 file changed

+10
-2
lines changed

modules/channel-web/src/views/lite/components/messages/renderer/FileMessage.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import mimeTypes from 'mime/lite'
2-
import path from 'path'
32
import React from 'react'
43

54
import { Renderer } from '../../../typings'
@@ -13,7 +12,16 @@ export const FileMessage = (props: Renderer.FileMessage) => {
1312

1413
const { url, title, storage, text } = props.file
1514

16-
const extension = path.extname(url)
15+
let extension = ''
16+
try {
17+
const validUrl = new URL(url)
18+
19+
extension = validUrl.pathname
20+
} catch (error) {
21+
// If the URL is not valid return a dummy component.
22+
return null
23+
}
24+
1725
const mime = mimeTypes.getType(extension)
1826

1927
if (text) {

0 commit comments

Comments
 (0)