jsvine / jsvine/notebookjs

Double-escape HTML when ansi is used

Open
#59 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
298
Forks
44
PR merge metrics
No merged PRs in 30d

Description

When using ansi_up for ansi conversion as documented in the README file, the HTML output is escaped twice. The cell contains:

...
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "'NoneType' object has no attribute 'call'",
     "output_type": "error",
     "traceback": [
      "\u001b[31m---------------------------------------------------------------------------\u001b[39m",
      "\u001b[31mAttributeError\u001b[39m                            Traceback (most recent call last)",
      "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[3]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m.call()\n",
      "\u001b[31mAttributeError\u001b[39m: 'NoneType' object has no attribute 'call'"
     ]
    }
   ],
   "source": [
    "None.call()"
   ]
  },
...

In particular note the use of ----->, which is created by the Python traceback. When I set nb.ansi = (code) => ansiUp.ansi_to_html(code), the resulting output has the > character escaped twice, once from notebookjs itself, and once from the nb.ansi() call (which also escapes HTML text). This seems to come from this code:
https://github.com/jsvine/notebookjs/blob/fb05a45a80f30951d7e03b70bb01d9260a0223a4/notebook.js#L194

One possible solution would be to replace the default for nb.ansi from ident to escapeHTML, then remove all calls to escapeHTML inside calls to nb.ansi. I'm happy to submit a PR if there is hope this would be reviewed/merged/released.

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

Start at notebook.js line 194 and compare the default nb.ansi behavior with the README's ansi_up usage. Trace the escaping applied by notebookjs and nb.ansi, then confirm that traceback characters such as > are escaped only once while other HTML output remains safe.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.