Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

json Invalid JSON text: "Invalid encoding in string." #73

Open
raybon-lee opened this issue Sep 22, 2021 · 0 comments
Open

json Invalid JSON text: "Invalid encoding in string." #73

raybon-lee opened this issue Sep 22, 2021 · 0 comments

Comments

@raybon-lee
Copy link

public static function mysql_escape($fieldValue)
  {
      if (is_array($fieldValue)) {
          return array_map(__METHOD__, $fieldValue);
      }

      if (is_bool($fieldValue)) {
          return (int)$fieldValue;
      }

      if (self::is_json($fieldValue)) {
           return self::safeJson($fieldValue);
      }

      if (!empty($fieldValue) && is_string($fieldValue)) {
          return str_replace(
              ['\\', "\0", "\n", "\r", "'", '"', "\x1a"],
              ['\\\\', '\\0', '\\n', '\\r', "\\'", '\\"', '\\Z'],
              $fieldValue
          );
      }

      return $fieldValue;
  }

replace

 public static function mysql_escape($fieldValue)
    {
        if (is_array($fieldValue)) {
            return array_map(__METHOD__, $fieldValue);
        }

        if (is_bool($fieldValue)) {
            return (int)$fieldValue;
        }

        if (self::is_json($fieldValue)) {
             fieldValue = self::safeJson($fieldValue);
        }

        if (!empty($fieldValue) && is_string($fieldValue)) {
            return str_replace(
                ['\\', "\0", "\n", "\r", "'", '"', "\x1a"],
                ['\\\\', '\\0', '\\n', '\\r', "\\'", '\\"', '\\Z'],
                $fieldValue
            );
        }

        return $fieldValue;
    }

note: The Json field may contain special characters of mysql, which should be handled again, not just the string type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant