Categories > TinyButStrong general >

max=100 doesn't cut off the first string

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: RwD
Date: 2005-03-08
Time: 15:44

max=100 doesn't cut off the first string

I am having the following template and php:
html:
<tr>
    <td>
        <h3>[overview.section_header; block=tr; max=50;.]</h3>
        <p>[overview.section_content; htmlconv=no; max=100;.]</p>
    </td>
</tr>

php:
$tbs->LoadTemplate( $dir['ptmpl'] . 'overview.htm' );

$query = "SELECT  `section_id`, `section_DOM_id`, `section_header`, `section_content`
          FROM `{$tbl['section']}`
          WHERE `section_class` = ''
          ORDER BY `section_id`";
$tbs->Mergeblock( 'overview', $DB->Link_ID, $query );

This results in the first row returned being its full length over 100 characters (424 in total) and all other rows being cut off at 100 chars exactly...

Perhaps I screwed up, but I got rid of all code possibly messing with the max=100 option and ended up with the code above and the problem :P
By: RwD
Date: 2005-03-08
Time: 15:49

Re: max=100 doesn't cut off the first string

It is getting stranger:

when I set max=42 everything works fine. When I set max=43 it doesn't work anymore.
By: Skrol29
Date: 2005-03-08
Time: 23:23

Re: max=100 doesn't cut off the first string

Can you provide the text stored in the database?
By: RwD
Date: 2005-03-09
Time: 12:17

Re: max=100 doesn't cut off the first string

I identified the problem, it is a bug!

It only occurs when the '&' character is used (by mistake, it should have been an &amp; entity). I think that if you precise the format of an entity that the bug is solved. So only accept a string as an enitity when it is without any spaces.

This is a teststring you can use:
<p>Lorem ipsum & dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
By: Skrol29
Date: 2005-03-09
Time: 14:03

Re: max=100 doesn't cut off the first string

Mmmmhhhh this is not really a TBS bug.
While "&" should be coded "&amp;", then recognizing the specific combination "& " (with a space) as a non Html entities is just correcting a user error. I know quite all web browsers fixe that problem, but I'm not sure that the template engine should do the same.
By: RwD
Date: 2005-03-09
Time: 17:05

Re: max=100 doesn't cut off the first string

So basically if I make a guestbook it is my job to put in &amp; instead of & in user posts is what you're saying.

But the problem here is the charcter-count. You introduced "entity-is-one-charcter" ones, after someone asked for it on the forum. I think that specific function should recognize wrong entities thought and nt count them as one char??
By: Skrol29
Date: 2005-03-09
Time: 18:20

Re: max=100 doesn't cut off the first string

> So basically if I make a guestbook it is my job to
> put in &amp; instead of & in user posts is what you're saying.

Yes of course. If you accept HTML content, then it's you application which has to check entered data, the Template Engine hasn't to fix bad user entry problems.

The first point is that TBS doesn't know HTML. Except for parameters 'max' and 'selected', otherwise, TBS can work with XML, PDF,... We can say TBS is oriented to Hml, but it hasn't to be specialized.

The second point is that you shouldn't ask user to enter HTML content. Except if the user is an admin which knows what's he's doing. Otherwise you'll have to check the validity of the entered HTML. And I promise you a nightmare, it won't stop at character "&" problem. That's why forums usually propose thier own special tags (BBcode for example), such tags  are much more easy to check and they limit the power of user's contents presentation.

> But the problem here is the charcter-count

Well, that's true parameter 'max' should count characters correctly.
I'll see if I can fix that easilly, but I'll know this feature can't go super far in the Html contents analizys.
By: RwD
Date: 2005-03-16
Time: 14:51

Re: max=100 doesn't cut off the first string

I understand user shouldn't do html. That's why I use wysiwyg inside webpages. but I strip out all buttons allowing different styles. I only allow them to use styles defined in the stylesheet.

But the problem happened because I manully copied and pasted the text I could see from a webpage into the database, that's when it happened and I noticed it. I was jsut saying that if you take entities into account you should do it right; there is a format for entities you can check against.