Skip to:
Content

Opened 18 months ago

Closed 18 months ago

Last modified 18 months ago

#3146 closed defect (fixed)

Convertor values passed to JS are cast to string

Reported by: jrf Owned by: johnjamesjacoby
Milestone: 2.6 Priority: high
Severity: normal Version: trunk
Component: API - Importers Keywords: has-patch commit
Cc: johnjamesjacoby, jrf

Description

Boolean and integer values passed to JS via wp_localize_script() will be converted to string *unless* they are within an array.

So the type casting done in the wp_localize_script() call in class-bbp-convertor.php is rendered useless as things stand now.

The net effect was the var being passed as follows (for a new import):

var BBP_Converter = {"ajax_nonce":"e5f8daf4fa","delay":"2","running":"","status":"","started":"","strings":{"button_start":"Start","button_continue":"Continue","start_start":"Starting Import...","start_continue":"Continuing Import...","import_complete":"Import Finished.","import_stopped_user":"Import Stopped (by User.)","import_error_halt":"Import Halted (Error.)","import_error_db":"Database Connection Failed.","status_complete":"Finished","status_stopped":"Stopped","status_starting":"Starting","status_up_next":"Doing step %s...","status_counting":"Next in %s..."}};

This was causing issues with the JS convertor script.

On top of that the comparison for whether or not the convertor had started was reversed.
This results in the "Continuing import" message being displayed on a new import instead of the "Starting import" message.

The attached patch will fix these issues in the simplest possible way.

With the patch applied, the var being passed will have the relevant subkeys in the correct variable type:

var BBP_Converter = {"ajax_nonce":"8cb79361eb","state":{"delay":2,"running":false,"status":false,"started":false},"strings":{"button_start":"Start","button_continue":"Continue","start_start":"Starting Import...","start_continue":"Continuing Import...","import_complete":"Import Finished.","import_stopped_user":"Import Stopped (by User.)","import_error_halt":"Import Halted (Error.)","import_error_db":"Database Connection Failed.","status_complete":"Finished","status_stopped":"Stopped","status_starting":"Starting","status_up_next":"Doing step %s...","status_counting":"Next in %s seconds..."}};

Attachments (1)

trac-3146-fix-passing-values-to-js.patch (4.1 KB) - added by jrf 18 months ago.

Download all attachments as: .zip

Change History (4)

#1 @johnjamesjacoby
18 months ago

  • Keywords commit added
  • Milestone changed from Awaiting Review to 2.6
  • Owner set to johnjamesjacoby
  • Priority changed from normal to high

Nice!

This looks great. Thanks a lot for catching this. It's all new code, so I appreciate your eyes on it.

Fix imminent.

#2 @johnjamesjacoby
18 months ago

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

In 6663:

Converter: ensure UI state variables are correctly localized.

This change combines the new UI state variables into an array, so they retain their type-casting through the localization API. It also inverts the logic in 1 comparison to make sure the correct user feedback is displayed in its intended location.

Trunk, for 2.6. Props jrf. Fixes #3146.

#3 @jrf
18 months ago

Glad to help. I had to get it fixed for something I'm working on anyway.

Note: See TracTickets for help on using tickets.