Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2012
    Location
    Upstate South Carolina
    Posts
    43
    Plugin Contributions
    1

    Default Text Attribute String Length

    We recently upgraded from 1.5.1 to 1.5.5b. Since then we have noticed some text attributes being truncated abnormally. I've setup a test site to demonstrate the issue. The site is a clean v1.5.5b with only one product. The product has two text attributes, Line 1 Text and Line 2 Text. They are the same except for the max length of Line 1 is 16 chars and Line 2 is 32 chars. The issue appears to be related to the max length.

    When I add an item to the cart using these strings as text attributes (Russian):

    ПОЛУ-АВТО
    АВТО РУЧНОЙ

    We see the text abnormally terminated in the cart. The issue only appears if the text entered is over 1/2 the max length. For Line 1, that is 8 chars, for Line 2 its 16.

    The string is terminated at the first ASCII character if there is one. Usually the space or hyphen if you're using the test text above. If you remove the space or hyphen, the string is terminated at 1/2 the max length.

    The test site is http://home.carolinalaserinc.com

    Any advice or help would be very much appreciated! I've banged my head on this on for two days to no avail. I cannot duplicate the issue in v1.5.1. For v1.5.1 we were using php 5.3, the 1.5.5b test site is using php 5.6.

  2. #2
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    9,218
    Plugin Contributions
    72

    Default Re: Text Attribute String Length

    What happens if you edit your copy (a core-file change, so be sure to make a backup) of /includes/functions/functions_general.php and change the zen_trunc_string function from
    Code:
    ////
    // Truncate a string
      function zen_trunc_string($str = "", $len = 150, $more = 'true') {
        if ($str == "") return $str;
        if (is_array($str)) return $str;
        $str = trim($str);
        $len = (int)$len;
        if ($len == 0) return '';
        // if it's les than the size given, then return it
        if (strlen($str) <= $len) return $str;
        // else get that size of text
        $str = substr($str, 0, $len);
        // backtrack to the end of a word
        if ($str != "") {
          // check to see if there are any spaces left
          if (!substr_count($str , " ")) {
            if ($more == 'true') $str .= "...";
            return $str;
          }
          // backtrack
          while(strlen($str) && ($str[strlen($str)-1] != " ")) {
            $str = substr($str, 0, -1);
          }
          $str = substr($str, 0, -1);
          if ($more == 'true') $str .= "...";
          if ($more != 'true' and $more != 'false') $str .= $more;
        }
        return $str;
      }
    to
    Code:
    ////
    // Truncate a string
      function zen_trunc_string($str = "", $len = 150, $more = 'true') {
        if ($str == "") return $str;
        if (is_array($str)) return $str;
        $str = trim($str);
        $len = (int)$len;
        if ($len == 0) return '';
        // if it's les than the size given, then return it
        if (mb_strlen($str) <= $len) return $str;
        // else get that size of text
        $str = mb_substr($str, 0, $len);
        // backtrack to the end of a word
        if ($str != "") {
          // check to see if there are any spaces left
          if (!mb_substr_count($str , " ")) {
            if ($more == 'true') $str .= "...";
            return $str;
          }
          // backtrack
          while(mb_strlen($str) && ($str[mb_strlen($str)-1] != " ")) {
            $str = mb_substr($str, 0, -1);
          }
          $str = mb_substr($str, 0, -1);
          if ($more == 'true') $str .= "...";
          if ($more != 'true' and $more != 'false') $str .= $more;
        }
        return $str;
      }
    ... essentially using the multi-byte (mb_) form of those string-related functions?

  3. #3
    Join Date
    Sep 2012
    Location
    Upstate South Carolina
    Posts
    43
    Plugin Contributions
    1

    Default Re: Text Attribute String Length

    Yes! Thank you very much, that fixed the problem in the test site.

  4. #4
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    9,218
    Plugin Contributions
    72

    Default Re: Text Attribute String Length

    Thanks for the follow-up that the suggested change corrects your issue. There are most likely other spots within the Zen Cart code that should be scrutinized for possible use of the multi-byte string functions, too.

    In the meantime, I've created an issue on the Zen Cart GitHub repository: https://github.com/zencart/zencart/issues/1387

 

 

Similar Threads

  1. string length in database
    By finlander in forum Templates, Stylesheets, Page Layout
    Replies: 3
    Last Post: 27 Jan 2011, 01:35 PM
  2. How to make text box attribute required and maximum length?
    By dgeere in forum Setting Up Categories, Products, Attributes
    Replies: 8
    Last Post: 20 Mar 2010, 11:10 AM
  3. Setting maximum string length for admin fields
    By numinix in forum Contribution-Writing Guidelines
    Replies: 0
    Last Post: 3 Jul 2007, 07:39 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR