Ticket #639 (closed bug: fixed)

Opened 2 months ago

Last modified 1 month ago

Mini-bug in jLocale

Reported by: Torgan Assigned to: laurentj
Priority: low Milestone: Jelix 1.0.5
Component: jelix:core:jLocale Version: 1.0.4
Severity: minor Keywords:
Cc: Php version:
Review: Hosting Provider:
Documentation needed: 0 Blocking:

Description

There is a mini-bug that results in notices in the method _loadResources of the jLocale class.

On line 121, we have :

                        if(preg_match("/^\s*(.*)\s*(\\\\?)$/U", $line, $match)){
                            $sp = preg_split('/(?<!\\\\)\#/', $match[1], -1 ,PREG_SPLIT_NO_EMPTY);
                            $multiline= ($match[2] =="\\");
                            $this->_strings[$charset][$key].=' '.trim(str_replace('\#','#',$sp[0]));
                        }else{
                            throw new Exception('Syntaxe error in file properties '.$fichier.' line '.$linenumber,210);
                        }

This raises a notice ([notice 1] Undefined offset: 0 /usr/local/share/jelix/lib/jelix/init.php 124) in this case :

text.key = youpi\
youpu\

text.key2 = youpa

That's because the first preg_match gets an empty string as $match[1] when parsing the 3rd line of text.key.

This could be a acceptable workaround :

                       if(preg_match("/^\s*(.*)\s*(\\\\?)$/U", $line, $match))
						{
                            $multiline= ($match[2] =="\\");
							
							if (strlen ($match[1]) > 0)
							{
								$sp = preg_split('/(?<!\\\\)\#/', $match[1], -1 ,PREG_SPLIT_NO_EMPTY);
								$this->_strings[$charset][$key].=' '.trim(str_replace('\#','#',$sp[0]));
							}
							else
							{
								$this->_strings[$charset][$key].=' ';
							}
                        }else{
                            throw new Exception('Syntaxe error in file properties '.$fichier.' line '.$linenumber,210);
                        }
  

Change History

07/04/08 13:45:28 changed by Julien

Hello,

I just saw this ticket, didn't test anything, but the manual says that there cannot be a trailing \ on the last line of a locale string.

So I think this will be marked as wontfix.

Maybe we should throw an Exception because the file has syntax errors (in you "else" statement) ?

So this whould become (need to test) :

if(preg_match("/^\s*(.*)\s*(\\\\?)$/U", $line, $match)){
    if(!isset($match[1]) || $match[1] === '')
        throw new Exception('Syntax error in file properties '.$fichier.' line '.$linenumber,210);
    $sp = preg_split('/(?<!\\\\)\#/', $match[1], -1 ,PREG_SPLIT_NO_EMPTY);
    $multiline= ($match[2] =="\\");
    $this->_strings[$charset][$key].=' '.trim(str_replace('\#','#',$sp[0]));
}
else{
    throw new Exception('Syntaxe error in file properties '.$fichier.' line '.$linenumber,210);
}

07/04/08 13:47:33 changed by Julien

arf, cannot edit previous comment :(

we really need jbugtracker ;)

"would" instead of "whould" of course...

07/04/08 13:47:45 changed by Julien

  • owner set to Julien.
  • status changed from new to assigned.

07/07/08 12:06:13 changed by laurentj

  • priority changed from normal to low.
  • component changed from jelix to jelix:core:jLocale.
  • severity changed from normal to minor.

07/23/08 21:17:07 changed by laurentj

  • owner changed from Julien to laurentj.
  • status changed from assigned to new.
  • milestone set to Jelix 1.0.5.

I made a unit test case and I confirm the bug. I take it to release the 1.0.5 with the bug fix.

@julien : it is a bug because the trailing \ is not at the last line, since the last line is the empty next line :-)

07/23/08 21:34:08 changed by laurentj

  • status changed from new to closed.
  • resolution set to fixed.

Fixed in the trunk and 1.0.x branch. The Torgan's patch works well.

07/25/08 10:53:09 changed by Julien

Hello,

ok, I thought that empty lines should be completely ignored ;)

so I could write something like (quite dumb right, but why not ?) :

my_string = this is a\
\
really stupid string ;)

my_second_string = hello

It works, but I see a little problem: linebreaks are converted as a space, so I have 2 spaces: "a" and "really" in the resulting string.

Wouldn't it be better to have the developer specify spaces explicitly ?

my_string = this is a \
\
really stupid string ;)

So jLocale does not add spaces automatically. I know it breaks compatibility with old behavior, I'm just asking.

07/25/08 11:49:04 changed by laurentj

Create a new ticket and we will discuss about it on this ticket.

Download in other formats: Comma-delimited Text Tab-delimited Text RSS Feed