Opened 10 years ago

Closed 10 years ago

#1559 closed defect (fixed)

DefinitionList <dl> button errors if cursor context is <body> elem

Reported by: ejucovy Owned by:
Priority: normal Milestone: 0.97
Component: Plugins Version: trunk
Severity: normal Keywords:


If the user presses the <dl> button (from the DefinitionList plugin) when the current context is text directly in the <body> element, the plugin throws a Javascript error:

Uncaught TypeError: Cannot call method 'toLowerCase' of undefined

The easiest way to reproduce is to click the button on an empty document, or on a document where you have typed text but never pressed enter.

The problem is that the plugin assumes that the current selection's parent element is a child of the body element:

    var pe = editor.getParentElement();
    while (pe.parentNode.tagName.toLowerCase() != 'body') {
      pe = pe.parentNode;

If editor.getParentElement() *is* the body element, this loop will walk up past it and end up at a node with no .parentElement.

The fix is to change the while loop's condition to

    while (pe.tagName.toLowerCase() != 'body')

Attachments (1)

bodyParentElement.diff (1000 bytes) - added by ejucovy 10 years ago.

Download all attachments as: .zip

Change History (3)

comment:1 Changed 10 years ago by ejucovy

Whoops, the proposed fix above is not correct -- it changes the behavior. We need to explicitly check for the edge case instead.

Changed 10 years ago by ejucovy

comment:2 Changed 10 years ago by ejucovy

  • Resolution set to fixed
  • Status changed from new to closed

Committed the above patch in r1273. Also, in r1274 I incremented the version of the plugin from 1.0 to 1.1 -- not sure if we have a standard way of doing plugin version numbers but I figured it couldn't hurt.

Note: See TracTickets for help on using tickets.