Code Monkey home page Code Monkey logo

Comments (4)

neffets avatar neffets commented on July 17, 2024

d6-issue-51.patch.txt

from drupal.

dsnopek avatar dsnopek commented on July 17, 2024

Fundamentally, this change makes sense to me! The code in the patch is actually from Drupal 7, in includes/json-encode.inc. I've made PR #56 which is working in my testing. Going to hold off for a bit to see if it can get a little more testing first.

from drupal.

amorsent avatar amorsent commented on July 17, 2024

I'm trying to reconcile these changes with Pressflow's changes to drupal_to_js().
You will have to address this conflict if you try to pull these changes into D6LTS Pressflow (it's a bit behind BTW)

Pressflow dropped all this custom code and just uses json_encode()
https://github.com/d6lts/pressflow/blob/master/includes/common.inc#L2563

function drupal_to_js($var) {
  // json_encode() does not escape <, > and &, so we do it with str_replace()
  return str_replace(array("<", ">", "&"), array('\u003c', '\u003e', '\u0026'), json_encode($var));
}

I've been using the Pressflow version for about a decade without issue.

The D7 code you refer to is actually a fallback to support PHP < 5.3
For PHP >= 5.3.0 D7's drupal_json_encode() actually just uses this:

// Encode <, >, ', &, and " using the json_encode() options parameter.
return json_encode($var, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT);

D8's version drop's the fallback logic and only uses the json_encode() logic.
https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Component%21Serialization%21Json.php/function/Json%3A%3Aencode/8.2.x

Differences:
The D7/8 version encodes ' and " characters where the Pressflow version does not.
The D7 fallback (and this current D6LTS version) encodes the following characters, where the D7/8 version leaves them un-encoded (but properly escaped):
"\", "\b", "\t", "\n", "\f", "\r", "/",

Is PHP < 5.3 support still a requirement for D6LTS?
If not, then it seems like we should probably just adopt the D7/8 json_encode() logic (which is similar, but an improvement to the version in Pressflow).

from drupal.

dsnopek avatar dsnopek commented on July 17, 2024

Is PHP < 5.3 support still a requirement for D6LTS?

Unfortunately, yes, we officially support PHP 5.2 and even have a couple stubborn customers that are still using it.

I believe Pressflow is PHP 5.3+ anyway, so I think it'd be fine if Pressflow didn't merge these changes and stuck with what it already has.

Also, I could see an argument for having D6LTS also check for PHP >=5.3 and using json_encode() - if someone made a PR for that, there's a strong chance it'd go in.

from drupal.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.