Download & Extend

alter drupal_to_js() to use json_encode()

Project:Drupal core
Version:7.x-dev
Component:javascript
Category:task
Priority:normal
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

Since we require PHP 5.2, we can rely instead on the built-in function json_encode()

http://www.php.net/manual/en/function.json-encode.php

Someone who knows more about the AHAH functionality should look at this- - also this change seem to break upload module's attach button, which suggests that there is some difference between the output of drupal_to_js() and json_encode()

AttachmentSizeStatusTest resultOperations
remove-drupal_to_js.patch5.19 KBIgnored: Check issue status.NoneNone

Comments

#1

Status:needs review» needs work

Ahh - investigation reveals that json_encode() does not escape < > or & the way drupal_to_js() does - thus there are HTML errors when the AHAH tries to get the updated form.

#2

Title:remove drupal_to_js()» alter drupal_to_js() to use json_encode()
Status:needs work» needs review

new patch - leave drupal_to_js() so we can escape to HTML-safe, but use the built-in json_encode() for efficiency.

With this the upload form AHAH, at least, seems to work right.

AttachmentSizeStatusTest resultOperations
improve-drupal_to_js-222578-2.patch1.82 KBIgnored: Check issue status.NoneNone

#3

Subscribing. Looking good! :)

#4

tested with PHP 5.2.4, Mac 10.4, FF 2.0 and Safari 3.0, apache 1.3:

book, upload, poll module AHA all works fine, user autocomplete field in node form works fine.

#5

Status:needs review» reviewed & tested by the community

Tested also in ie6 and ie7. Poll, book, upload and autocomplete all work.

#6

Status:reviewed & tested by the community» fixed

I committed this to CVS HEAD. Thanks.

#7

Status:fixed» active

Note: I asked Steven about why he introduced the escaping in the first place, since everything seems to work fine without. The reason he put that into place is because it was required for the upload.module's iframe mechanism. This however, has been removed (and replaced with AHAH). That means, that we can get rid of the encoding after we tested that everything still works.

#8

@kk - during my testing it did NOT work when the escaping was removed. See the first patch.

#9

Status:active» fixed

back to fixed

#10

Status:fixed» closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

#11

Version:7.x-dev» 6.x-dev
Status:closed (fixed)» patch (to be ported)

Does this need backporting to d6 (in order to help with upgrade to jQuery 1.4.x)?

PS: Changed status in order to gain some attention - don't mean to bust anyone's b@lls here. Feel free to change back if it is irrelevant, but it does seem to solve this #818138: jQuery 1.4.x compatibility in Hierarchical Select.

#12

Version:6.x-dev» 7.x-dev
Status:patch (to be ported)» closed (fixed)

I think this is closed in terms of core, certainly for Drupal 6.x.

#13

Care to explain why Peter? Is it because d7 requires php 5.2 (that has json_encode() built-in) while d6 requires 4.4+ instead? If so, I think there could be a check to detect php version and then if >5.2 use json_encode(), if <5.2 use drupal_to_js().

nobody click here