Bug Tracker

Modify

Ticket #6884 (closed bug: duplicate)

Opened 3 years ago

Last modified 3 years ago

XML introspection confused when SVG embedded in <script> tag

Reported by: cefn Owned by:
Priority: low Milestone: 1.5
Component: attributes Version: 1.4.2
Keywords: xml svg attr setAttribute Cc:
Blocking: Blocked by:

Description

Using attr(map) to set attributes on embedded SVG elements triggers an error in JQuery, whilst directly setting the attributes works fine.

I'm following instructions in the SVGWeb tutorial to embed SVG in the page, using a script tag with type="image/svg+xml"  http://codinginparadise.org/projects/svgweb/docs/QuickStart.html I understand this is supported by many browsers.

JQuery introspects elements to judge whether or not it should use setAttribute(name,value) for XML documents or elem[name]=value for DOM0 documents, but the logic doesn't detect that this SVG element actually requires the setAttribute(...) style invocation suitable for XML.

The logic in 1.4.2 looks like this...

var notxml = elem.nodeType !== 1
!jQuery.isXMLDoc( elem )

...and attr() falls through to Line 1493 calling...

elem[ name ] = value;

...triggering the error "setting a property that has only a getter"

The example code at  http://pastebin.com/U1kyLxVE contains an attr() call which triggers the error, and contains a commented version of equivalent setAttribute calls which do not trigger the error.

The logic of 'notxml' should be modified to capture such cases and make attr() work. For example, the namespaceURI of this element is  http://www.w3.org/2000/svg so it is indeed possible to detect the case.

Change History

comment:1 Changed 3 years ago by SlexAxton

  • Priority set to low
  • Status changed from new to open
  • Component changed from unfiled to attributes
  • Milestone changed from 1.4.3 to 1.5

comment:2 Changed 3 years ago by snover

  • Status changed from open to closed
  • Resolution set to duplicate

comment:3 Changed 3 years ago by snover

Duplicate of #3116.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.