In entity_metadata_field_get_language() the default language is determined using the following:
$default_langcode = isset($entity->language) ? $entity->language : LANGUAGE_NONE;

However, if no language is set for the entity, $entity->language may be set to an empty string (''). This causes isset() to return TRUE and ends up returning an empty string if $langcode == LANGUAGE_NONE due to the following a few lines lower:
$langcode = ($langcode != LANGUAGE_NONE) ? field_valid_language($langcode, $default_langcode) : $default_langcode;

The line to determine the the default language should use !empty() instead, this will cover situations where it is not set as well as situations where it is set to NULL or an empty string.

#1 use-empty-for-entity-language-1703146-1.patch815 bytesBassistJimmyJam
PASSED: [[SimpleTest]]: [MySQL] 354 pass(es). View


BassistJimmyJam’s picture

Status: Active » Needs review
815 bytes
PASSED: [[SimpleTest]]: [MySQL] 354 pass(es). View

Patch attached.

fago’s picture

Status: Needs review » Fixed

well, I don't think the entity should have '' or FALSE as langcode, but still this makes our code more safe so let's do it.

Committed, thanks.

Status: Fixed » Closed (fixed)

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

EclipseGc’s picture

Status: Closed (fixed) » Active

This bug alone has cost me literally hours to debug and trace. in Later php 5.3 versions (10+ I know for sure) $entity->language can come across set to NULL. At the very least this warrants a new point release of entity api. PLEASE :-) It'll start biting other people soon, I found and fixed this for myself and then came looking for an corresponding issue. Marking active again in the hopes of getting enough attention for a new release of the module. Thanks


mitchell’s picture

Status: Active » Closed (fixed)
mitchell’s picture

Issue summary: View changes

Updated issue summary.