Skip to content

Commit

Permalink
Truncate extra-long titles, to prevent SQL errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
eheikes committed May 9, 2017
1 parent 1b1452a commit 84c8e8f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion toreadapi.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ function getEntry() {
function postEntry() {
global $dbh;

$maxTitleLength = 191;

$postdata = file_get_contents("php://input");
$POST = json_decode($postdata);
$url = isset($POST->url) ? $POST->url : '';
Expand Down Expand Up @@ -245,7 +247,7 @@ function postEntry() {
if (preg_match("#<title[^>]*>(.*)</title>#iU", $result, $matches)
and $matches[1] != "")
{
$title = $matches[1];
$title = mb_substr($matches[1], 0, $maxTitleLength, 'UTF-8');
}
// Save the page, if it's HTML.
if (stripos($result, '<html') !== false) {
Expand Down

0 comments on commit 84c8e8f

Please sign in to comment.