developer.jelix.org is not used any more and exists only for history. Post new tickets on the Github account.
developer.jelix.org n'est plus utilisée, et existe uniquement pour son historique. Postez les nouveaux tickets sur le compte github.

Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#639 closed bug (fixed)

Mini-bug in jLocale

Reported by: Torgan Owned by: laurentj
Priority: low Milestone: Jelix 1.0.5
Component: jelix:core:jLocale Version: 1.0.4
Severity: minor Keywords:
Cc: Blocked By:
Blocking: Documentation needed: no
Hosting Provider: Php version:

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 (8)

comment:1 Changed 12 years ago 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);
}

comment:2 Changed 12 years ago by Julien

arf, cannot edit previous comment :(

we really need jbugtracker ;)

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

comment:3 Changed 12 years ago by Julien

  • Owner set to Julien
  • Status changed from new to assigned

comment:4 Changed 12 years ago by laurentj

  • Component changed from jelix to jelix:core:jLocale
  • Priority changed from normal to low
  • Severity changed from normal to minor

comment:5 Changed 12 years ago by laurentj

  • Milestone set to Jelix 1.0.5
  • Owner changed from Julien to laurentj
  • Status changed from assigned to new

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 :-)

comment:6 Changed 12 years ago by laurentj

  • Resolution set to fixed
  • Status changed from new to closed

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

comment:7 Changed 12 years ago 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.

comment:8 Changed 12 years ago by laurentj

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

Note: See TracTickets for help on using tickets.