Skip to content

Commit

Permalink
Fix 60879
Browse files Browse the repository at this point in the history
  • Loading branch information
larkox committed Nov 13, 2024
1 parent 6e032a7 commit 26f7b35
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/components/document/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const Document = forwardRef<DocumentRef, DocumentProps>(({canDownloadFiles, chil
setPreview(true);
setStatusBarColor('dark-content');
FileViewer.open(path!.replace('file://', ''), {
displayName: decodeURIComponent(file.name),
displayName: file.name,
onDismiss: onDonePreviewingFile,
showOpenWithDialog: true,
showAppsSuggestions: true,
Expand Down
2 changes: 1 addition & 1 deletion app/components/files/file_info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const FileInfo = ({disabled, file, channelName, showDate, onPress}: FileInfoProp
ellipsizeMode='tail'
style={style.fileName}
>
{decodeURIComponent(file.name.trim())}
{file.name.trim()}
</Text>
<View style={style.fileDownloadContainer}>
{channelName &&
Expand Down
4 changes: 2 additions & 2 deletions app/components/markdown/markdown_image/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {bottomSheetSnapPoint} from '@utils/helpers';
import {calculateDimensions, getViewPortWidth, isGifTooLarge} from '@utils/images';
import {getMarkdownImageSize} from '@utils/markdown';
import {changeOpacity, makeStyleSheetFromTheme} from '@utils/theme';
import {normalizeProtocol, tryOpenURL} from '@utils/url';
import {normalizeProtocol, safeDecodeURIComponent, tryOpenURL} from '@utils/url';

import type {GalleryItemType} from '@typings/screens/gallery';

Expand Down Expand Up @@ -88,7 +88,7 @@ const MarkdownImage = ({
const uri = source.startsWith('/') ? serverUrl + source : source;

const fileInfo = useMemo(() => {
const link = decodeURIComponent(uri);
const link = safeDecodeURIComponent(uri);
let filename = parseUrl(link.substr(link.lastIndexOf('/'))).pathname.replace('/', '');
let extension = metadata?.format || filename.split('.').pop();
if (extension === filename) {
Expand Down
3 changes: 2 additions & 1 deletion app/components/markdown/markdown_table_image/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {useGalleryItem} from '@hooks/gallery';
import {fileToGalleryItem, openGalleryAtIndex} from '@utils/gallery';
import {generateId} from '@utils/general';
import {calculateDimensions, isGifTooLarge} from '@utils/images';
import {safeDecodeURIComponent} from '@utils/url';

import type {GalleryItemType} from '@typings/screens/gallery';

Expand Down Expand Up @@ -57,7 +58,7 @@ const MarkTableImage = ({disabled, imagesMetadata, location, postId, serverURL,
const getFileInfo = () => {
const height = metadata?.height || 0;
const width = metadata?.width || 0;
const link = decodeURIComponent(getImageSource());
const link = safeDecodeURIComponent(getImageSource());
let filename = parseUrl(link.substr(link.lastIndexOf('/'))).pathname.replace('/', '');
let extension = filename.split('.').pop();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ const BookmarkFile = ({channelId, close, disabled, initialFile, maxFileSize, set
ellipsizeMode='tail'
style={styles.filename}
>
{decodeURIComponent(file.name.trim())}
{file.name.trim()}
</Text>
{info}
</View>
Expand Down
4 changes: 2 additions & 2 deletions app/screens/channel_bookmark/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,13 @@ const ChannelBookmarkAddOrEdit = ({
...(bookmark || emptyBookmark),
owner_id: ownerId,
channel_id: channelId,
display_name: decodeURIComponent(f.name),
display_name: f.name,
type: 'file',
file_id: f.id,
};
setBookmarkToSave(b);
setFile(f);
}, [bookmark, channelId, ownerId]);
}, [bookmark, channelId, ownerId, setBookmarkToSave]);

const setBookmarkDisplayName = useCallback((displayName: string) => {
if (bookmark) {
Expand Down
3 changes: 2 additions & 1 deletion app/utils/file/file_picker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Permissions from 'react-native-permissions';
import {dismissBottomSheet} from '@screens/navigation';
import {extractFileInfo, lookupMimeType} from '@utils/file';
import {logWarning} from '@utils/log';
import {safeDecodeURIComponent} from '@utils/url';

import type {IntlShape} from 'react-intl';

Expand Down Expand Up @@ -128,7 +129,7 @@ export default class FilePickerUtil {
const type = file.type || lookupMimeType(uri);
let fileName = file.fileName;
if (type.includes('video/') && uri) {
fileName = decodeURIComponent(uri.split('\\').pop()?.split('/').pop() || '');
fileName = safeDecodeURIComponent(uri.split('\\').pop()?.split('/').pop() || '');
}

if (uri) {
Expand Down
9 changes: 9 additions & 0 deletions app/utils/url/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,12 @@ export function extractFilenameFromUrl(url: string) {
const uri = urlParse(url);
return uri.pathname.split('/').pop();
}

export function safeDecodeURIComponent(v: string) {
try {
const result = decodeURIComponent(v);
return result;
} catch {
return v;
}
}

0 comments on commit 26f7b35

Please sign in to comment.