I am using the HTTP Fetcher and the Common syndication parser to import from http://widget.websta.me/rss/n/mitadmissions.

There are emojis in the content and they trigger the following error(s):

PDOException: SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\xF0\x9F\x8C\xB7\xF0\x9F...' for column 'title' at row 1: INSERT INTO {node} (type, language, title, uid, status, created, changed, comment, promote, sticky) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9); Array ( [:db_insert_placeholder_0] => instagram [:db_insert_placeholder_1] => und [:db_insert_placeholder_2] => nbd just petting some ducklings at MIT Day of Play #SpringIt [emoji] [:db_insert_placeholder_3] => 0 [:db_insert_placeholder_4] => 1 [:db_insert_placeholder_5] => 1454100554 [:db_insert_placeholder_6] => 1454100554 [:db_insert_placeholder_7] => 2 [:db_insert_placeholder_8] => 1 [:db_insert_placeholder_9] => 0 ) in drupal_write_record() (line 7333 of /[redacted]/includes/common.inc).

I found a related report and patch:
Feeds JSONPath Parser » Issues » When importing Tweets: SQLSTATE[HY000]: General error: 1366 Incorrect string value

I'm in the process of bringing this patch to plugins/FeedsSyndicationParser.inc but won't finish until Monday.

Comments

karenann created an issue. See original summary.

karenann’s picture

It is interesting to note that the first 3 times I tried to submit this bug report, I got a 5xx error.

I removed the emojis from the description and it posted.

megachriz’s picture

This sounds like that is not specific to Feeds.

These issues may be related:

Great that are you working on it! Maybe you also want to include an automated test with your patch? This way we can ensure that the problem doesn't come back. It is also handy to have a test so it can be fixed in the D8 version as well at some point.

karenann’s picture

I see an automated test with the patch I'm using as a reference, but I have limited experience with tests. I'll try, but if I can't make the time for it, I'll still post the patch and ask if someone else can contribute faster than I.

And, yes, this is not at all limited to Feeds.

In my original post, where you see the word [emoji], I had to remove two emoji chars because this d-dot-org form 500 errored out with them in.

If you want to see the specific chars, go to http://widget.websta.me/rss/n/mitadmissions and find the text "nbd just petting some ducklings at MIT Day of Play"

I have a note to report the bug elsewhere, but time is finite.

I'm working on the patch for this today, though.

megachriz’s picture

No problem. A patch with just the fix is a great start. If you do not find time to write a test, perhaps you want to compose a sample file with the emoji in it? This file could then be used for the automated test. I know you provided a link to a file with emoji in it, but for the test we would need a file with dummy data. It is better not to use real data for tests (for example, because of copyrights).

karenann’s picture

I'm attaching a stripped down html file with a .txt added to the filename to allow it to be uploaded (html files are disallowed).

This is a minimal sample of the offending code.

Here's how the matching works (only grabs the first emoji if multiple):

// Regex swiped from patch #22 in issue # 1824506
$fourByteRegex = '/(?:\xF0[\x90-\xBF][\x80-\xBF]{2}|[\xF1-\xF3][\x80-\xBF]{3}|\xF4[\x80-\x8F][\x80-\xBF]{2})/s';

// Loop through my offending strings
foreach ($myevalstring as $string) {

  // Strip out all but the offending emoji
  preg_match($fourByteRegex, $string, $match);

  // If we have an offender
  if ($match) {

    // Add the string back to the array for reference
    $match['string'] = $string;

    // Spit it out
    drupal_set_message('<pre>' . print_r($match, true) . '</pre>');
  }
}

// Remove all the extraneous HTML from file by hand
// Add a .txt so I can upload to Drupal.org
// Provide a screenshot in case it looks different for other people
karenann’s picture

Status: Active » Needs review
StatusFileSize
new3.92 KB

I am attaching a patch and have notes:

  • Used code from #1824506: When importing Tweets: SQLSTATE[HY000]: General error: 1366 Incorrect string value #22
  • I did not write tests, though some exist in the source from #1824506, patch in #22.
  • I did not implement the config option to convert versus strip. It will always strip.
  • I did test the convert and it does work. However, I had subsequent failures because the path module wasn't stripping the emojis in the alias path and then the same errors would fire for the {url_alias} table.
  • I did not address this issue for any of the other Feeds plugins.

Basically, this isn't packaged up nicely for distro, but I am out of time for now. If someone else can contribute, awesome. If not, I'll try and check back again when I can.

karenann’s picture

karenann’s picture

@raphaeldelrosal

I'm just seeing that you PMed me to get a copy of the file after the patch is applied. I'm guessing because you aren't familiar with how to apply a patch.

Normally, it's best to test a patch by figuring out how to apply it and test then. I'd read up on patching as it's a skill you will benefit from having. For me, I usually put my patches in sites/all/patches and then cd into the module I'm patching and patch -p1 < ../../patches/thepatch.patch. That's just my workflow. It may not be anyone else's.

That said, check out the link in comment #9. Drupal 7.50 may address this issue but I haven't had a chance to test it. And I don't think I will anytime soon.

bluegeek9’s picture

Status: Needs review » Closed (outdated)

Drupal 7 reached end of life and the D7 version of Feeds is no longer being developed. To keep the issue queue focused on supported versions, we’re closing older D7 issues.

If you still have questions about using Feeds on Drupal 7, feel free to ask. While we won’t fix D7 bugs anymore, we’re happy to offer guidance to help you move forward. You can do so by opening (or reopening) a D7 issue, or by reaching out in the #feeds channel on Drupal Slack.

If this issue is still relevant for Drupal 10+, please open a follow-up issue or merge request with proposed changes. Contributions are always welcome!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.