MCPcopy Create free account
hub / github.com/OpenHands/OpenHands / looksLikeWorkspaceFilePath

Function looksLikeWorkspaceFilePath

src/utils/path-utils.ts:82–104  ·  view source on GitHub ↗
(text: string)

Source from the content-addressed store, hash-verified

80 * Rejects URLs, MIME types, versions, and dotted identifiers like `console.log`.
81 */
82export const looksLikeWorkspaceFilePath = (text: string): boolean => {
83 const trimmed = text.trim();
84 if (!trimmed || /\s/.test(trimmed) || /^https?:\/\//i.test(trimmed)) {
85 return false;
86 }
87
88 let path = trimmed.replace(/\\/g, "/").replace(/^\.\//, "");
89 path = path.replace(/:(\d+)(-\d+)?$/, "");
90
91 if (
92 /^(application|audio|image|text|video|font|multipart|message|model)\/[\w.+-]+$/i.test(
93 path,
94 )
95 ) {
96 return false;
97 }
98 if (/^v?\d+(\.\d+){1,3}([-+][\w.]+)?$/i.test(path)) {
99 return false;
100 }
101
102 const lastSegment = path.includes("/") ? (path.split("/").pop() ?? "") : path;
103 return WORKSPACE_FILE_EXTENSION.test(lastSegment);
104};
105
106/**
107 * Returns the basename (top-level folder/file name) from a path string,

Callers 2

useExistingWorkspacePathFunction · 0.90
path-utils.test.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected