in views_views_json_style.theme.inc, use html_entity_decode() when the option for plaintext_output = TRUE and "field_output" = normal.
This way, HTML entities that come from field values are made into true plain text.
We also must ensure that the field output is UTF-8, in order to be compliant with JSON.

$content = $plaintext_output ? strip_tags($field->content) : $field->content;

Becomes:

$content = $plaintext_output ? strip_tags(html_entity_decode($field->content, ENT_QUOTES)) : $field->content;
$content = mb_check_encoding($content, 'UTF-8') ? $content : utf8_encode($content);

This functionality is already in place for view_xml plugin. See /views/theme/views_view.xml_style.theme.inc

We use the ENT_QUOTES option to convert single and double quotes (') and ("") as those are commonly encoded entities by Drupal Core.
Example is with Node titles. As of Drupal 7, all node titles are run through htmlentities(), so characters like apostrophes become ', when in reality we want an actual apostrophe in our plaintext output.

Patch below.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

lookatthosemoose’s picture

lookatthosemoose’s picture

New patch that include the UTF-8 checking. Disregard last patch.

kriskhaira’s picture

I get the following error while trying to apply the patch.

patch: **** malformed patch at line 13: $content = array();

I then manually applied the changes but don't see any changes in the JSON output.

kriskhaira’s picture

Correction: the changes work (I had accidentally switched off plaintext_output), but I still needed to make the changes manually.

I'm attaching a patch I created - same changes, just recreated with different line number references.

davidneedham’s picture

The patch in #4 applies successfully, but my json feed continues to output '. I've verified that my cache is flushed and the code was changed appropriately

davidneedham’s picture

Status: Needs review » Reviewed & tested by the community

Actually, I did exactly the same thing as @ kriskhaira. Once you enable plaintext output, it works perfectly.

davidneedham’s picture

Issue summary: View changes

Addition to code example.

Anonymous’s picture

Jibus’s picture

Patch #7 resolves the issue ! Thanks ! Hope this will get commited soon :)

anthonylindsay’s picture

Status: Reviewed & tested by the community » Fixed

#7 looks good to me. Committing to 7.x branch.

anthonylindsay’s picture

Status: Fixed » Closed (fixed)

Closing.

jcisio’s picture

Version: 7.x-1.x-dev » 6.x-1.x-dev
Status: Closed (fixed) » Needs review
FileSize
2.87 KB

Same issue and same fix in D6.

  • yannickoo committed bdb25ad on 6.x-1.x authored by jcisio
    Issue #1915492 by lookatthosemoose, jcisio, rsmylski, kriskhaira: Fixed...
yannickoo’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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