Macaulay2 / Macaulay2/M2

realpath rejects `#`

Open
#4,442 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Core
Dominant language
Macaulay2
Stars
435
Forks
297
Avg merge
4d 20h
Merged PRs (30d)
11

Description

This section of hypertext.m2 is problematic:
```
fileExists' = pth -> (
if match("#",pth) then pth = substring(0,lastMatch#0#0,pth);
fileExists pth
)

-- TODO: phase this one out eventually
toURL = method()
toURL String := pth -> (
urlEncode if isAbsolutePath pth then concatenate(rootURI,
if fileExists' pth then realpath pth
```
Note that `fileExists` has been modified to allow extra `#` information after the file name, which is typically used by `FilePosition` and error messages.
There's a first basic issue which is, what if a filename contains a `#`?
In any case, a more fundamental problem is that `pth` is fed directly to `realpath` without removing the `#` part.
On my laptop, `realpath` rejects filenames with a `#` -- more precisely, it sends EONENT (i.e., file not found, as it should), though that signal is not correctly forwarded to M2, because stat(NULL) replaces ENOENT with EFAULT (“Bad address”), resulting in the cryptic error message
```
i18 : toURL "/home/pzinn/M2/M2/Macaulay2/m2/hypertext.m2#L451:C26-L453:C15"
stdio:18:5:(3):[1]: error: realpath failed: Bad address
```
I've only started encountering this problem recently (in fact, on the Macaulay2Web server, realpath seems happy with `#`), so not sure what exactly changed. but there's definitely an issue.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Inspect hypertext.m2 around fileExists' and toURL, then reproduce the reported toURL call with a path containing #. Determine how the # metadata is handled before realpath, including the filename case, and verify that the resulting error is no longer the reported failure.

Written by the indexing model from the issue text.

Assessment

Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.