WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 9 months ago

#20450 closed defect (bug) (wontfix)

wp_dropdown_categories - inconsistent use of single-quotes causes (javascript) assignment issues

Reported by: rcain Owned by:
Milestone: Priority: normal
Severity: minor Version: 3.3.1
Component: Template Keywords: has-patch
Focuses: Cc:

Description

wp_dropdown_categories outputs double-quote characters for all options (value etc) BUT single-quote characters for main select attributes - which is inconsistent.

this causes a problem when assigning output to eg. a javascript string - meaning we must perform a separate 'replace' operation first.

similarly, we already have to do a replace of all newline-characters in output for newline-backslash - in order that its multi-line output can be assigned to a javascript variable.

please could we have double-quote characters used consistently in output? ideally provision of a javascript friendly output format (ie. backslash-newline) would also be great - though my no means essential.

Attachments (1)

20450.diff (2.0 KB) - added by CoenJacobs 2 years ago.
Basic fix to rewrite the entire element to double-quote characters

Download all attachments as: .zip

Change History (4)

CoenJacobs2 years ago

Basic fix to rewrite the entire element to double-quote characters

comment:1 CoenJacobs2 years ago

  • Keywords has-patch added

Pretty easy to fix. Not sure why this was done this way, probably for easier echo'ing.

comment:2 in reply to: ↑ description nacin22 months ago

  • Keywords close added

Replying to rcain:

please could we have double-quote characters used consistently in output? ideally provision of a javascript friendly output format (ie. backslash-newline) would also be great - though my no means essential.

I don't really like this. We use single quotes all over in core, as often it is going to be a cleaner line of PHP code to use them (for example, when using variables inside double-quoted strings). While we could make this change, it would imply that we are then committing to always using double-quotes now and in the future, for all output functions. We simply cannot commit to that.

If you want to use raw HTML output in JS, you should escape it or json-encode it.

comment:3 SergeyBiryukov9 months ago

  • Component changed from General to Template
  • Keywords close removed
  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

Related/duplicate: #23305

Note: See TracTickets for help on using tickets.