1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-11-23 22:36:32 +02:00

Server: Improve error when attempting to load certain routes that do not exist (#13683)

This commit is contained in:
Henry Heino
2025-11-15 00:58:36 -08:00
committed by GitHub
parent 4a0d9220ba
commit 9e9d2699b5
3 changed files with 9 additions and 3 deletions

View File

@@ -8,6 +8,7 @@ import { AppContext, RouteType } from '../utils/types';
import { localFileFromUrl } from '../utils/joplinUtils';
import { homeUrl, loginUrl } from '../utils/urlUtils';
import * as mime from '@joplin/lib/mime-utils';
import { hasOwnProperty } from '@joplin/utils/object';
const publicDir = `${dirname(dirname(__dirname))}/public`;
@@ -33,7 +34,7 @@ async function findLocalFile(path: string): Promise<string> {
const appFilePath = await localFileFromUrl(path);
if (appFilePath) return appFilePath;
if (path in pathToFileMap) return pathToFileMap[path];
if (hasOwnProperty(pathToFileMap, path)) return pathToFileMap[path];
// For now a bit of a hack to load FontAwesome fonts.
if (path.indexOf('css/fontawesome/webfonts/fa-') === 0) return `node_modules/@fortawesome/fontawesome-free/${path.substr(16)}`;

View File

@@ -7,6 +7,7 @@ import { URL } from 'url';
import { csrfCheck } from './csrf';
import { contextSessionId } from './requestUtils';
import { stripOffQueryParameters } from './urlUtils';
import { hasOwnProperty } from '@joplin/utils/object';
const { ltrimSlashes, rtrimSlashes } = require('@joplin/lib/path-utils');
@@ -262,7 +263,7 @@ export function findMatchingRoute(path: string, routes: Routers): MatchedRoute {
// Create the base path, eg. "api/files", to match it to one of the
// routes.
const basePath = `${namespace ? `${namespace}/` : ''}${splittedPath[0]}/${splittedPath[1]}`;
if (routes[basePath]) {
if (hasOwnProperty(routes, basePath)) {
// Remove the base path from the array so that parseSubPath() can
// extract the ID and link from the URL. So the array will contain
// at this point: ['SOME_ID', 'content'].
@@ -278,7 +279,7 @@ export function findMatchingRoute(path: string, routes: Routers): MatchedRoute {
// Paths such as "/users/:id" or "/apps/joplin/notes/:id" will get here
const basePath = splittedPath[0];
const basePathNS = (namespace ? `${namespace}/` : '') + basePath;
if (routes[basePathNS]) {
if (hasOwnProperty(routes, basePathNS)) {
splittedPath.splice(0, 1);
return {
route: routes[basePathNS],

View File

@@ -15,3 +15,7 @@ export function checkObjectHasProperties(object: any, properties: string[]) {
if (!(prop in object)) throw new Error(`Missing property "${prop}": ${JSON.stringify(object)}`);
}
}
export const hasOwnProperty = (object: object, property: string): boolean => {
return !!object && Object.prototype.hasOwnProperty.call(object, property);
};