diff --git a/src/Illuminate/Translation/Translator.php b/src/Illuminate/Translation/Translator.php index 6faf6b31c40a..8ff19ae9b7a8 100755 --- a/src/Illuminate/Translation/Translator.php +++ b/src/Illuminate/Translation/Translator.php @@ -264,6 +264,8 @@ protected function makeReplacements($line, array $replace) $replace = $this->sortReplacements($replace); foreach ($replace as $key => $value) { + $value = e($value); + $line = str_replace( [':'.$key, ':'.Str::upper($key), ':'.Str::ucfirst($key)], [$value, Str::upper($value), Str::ucfirst($value)], diff --git a/src/Illuminate/View/Compilers/Concerns/CompilesTranslations.php b/src/Illuminate/View/Compilers/Concerns/CompilesTranslations.php index bdc071a65a01..feb7e6510c6b 100644 --- a/src/Illuminate/View/Compilers/Concerns/CompilesTranslations.php +++ b/src/Illuminate/View/Compilers/Concerns/CompilesTranslations.php @@ -18,7 +18,7 @@ protected function compileLang($expression) return "startTranslation{$expression}; ?>"; } - return "getFromJson{$expression}); ?>"; + return "getFromJson{$expression}; ?>"; } /** @@ -28,7 +28,7 @@ protected function compileLang($expression) */ protected function compileEndlang() { - return 'renderTranslation()); ?>'; + return 'renderTranslation(); ?>'; } /** @@ -39,6 +39,6 @@ protected function compileEndlang() */ protected function compileChoice($expression) { - return "choice{$expression}); ?>"; + return "choice{$expression}; ?>"; } } diff --git a/tests/Translation/TranslationTranslatorTest.php b/tests/Translation/TranslationTranslatorTest.php index cd0c8f018dc3..a9d3d36dc3aa 100755 --- a/tests/Translation/TranslationTranslatorTest.php +++ b/tests/Translation/TranslationTranslatorTest.php @@ -49,6 +49,20 @@ public function testGetMethodProperlyLoadsAndRetrievesItem() $this->assertEquals('foo', $t->get('foo::bar.foo')); } + public function testTransMethodProperlyLoadsAndRetrievesItemWithHTMLReplacements() + { + $t = new \Illuminate\Translation\Translator($this->getLoader(), 'en'); + $t->getLoader()->shouldReceive('load')->once()->with('en', 'foo', '*')->andReturn(['bar' => 'breeze :foo']); + $this->assertSame('breeze <p>test</p>', $t->trans('foo.bar', ['foo' => '
test
'], 'en')); + } + + public function testTransMethodProperlyLoadsAndRetrievesItemWithHTMLInTheMessage() + { + $t = new \Illuminate\Translation\Translator($this->getLoader(), 'en'); + $t->getLoader()->shouldReceive('load')->once()->with('en', 'foo', '*')->andReturn(['bar' => 'breezetest
']); + $this->assertSame('breezetest
', $t->trans('foo.bar', [], 'en')); + } + public function testGetMethodProperlyLoadsAndRetrievesItemWithCapitalization() { $t = $this->getMockBuilder('Illuminate\Translation\Translator')->setMethods(null)->setConstructorArgs([$this->getLoader(), 'en'])->getMock(); diff --git a/tests/View/Blade/BladeExpressionTest.php b/tests/View/Blade/BladeExpressionTest.php index c25891ddbe56..930b48e51ae9 100644 --- a/tests/View/Blade/BladeExpressionTest.php +++ b/tests/View/Blade/BladeExpressionTest.php @@ -6,13 +6,13 @@ class BladeExpressionTest extends AbstractBladeTestCase { public function testExpressionsOnTheSameLine() { - $this->assertEquals('getFromJson(foo(bar(baz(qux(breeze())))))); ?> space () getFromJson(foo(bar))); ?>', $this->compiler->compileString('@lang(foo(bar(baz(qux(breeze()))))) space () @lang(foo(bar))')); + $this->assertEquals('getFromJson(foo(bar(baz(qux(breeze()))))); ?> space () getFromJson(foo(bar)); ?>', $this->compiler->compileString('@lang(foo(bar(baz(qux(breeze()))))) space () @lang(foo(bar))')); } public function testExpressionWithinHTML() { $this->assertEquals('>', $this->compiler->compileString('')); $this->assertEquals('>', $this->compiler->compileString('')); - $this->assertEquals(' getFromJson(\'foo\')); ?>>', $this->compiler->compileString('')); + $this->assertEquals(' getFromJson(\'foo\'); ?>>', $this->compiler->compileString('')); } } diff --git a/tests/View/Blade/BladeLangTest.php b/tests/View/Blade/BladeLangTest.php index c5232614cc6a..6f32cac6543d 100644 --- a/tests/View/Blade/BladeLangTest.php +++ b/tests/View/Blade/BladeLangTest.php @@ -7,13 +7,13 @@ class BladeLangTest extends AbstractBladeTestCase public function testStatementThatContainsNonConsecutiveParenthesisAreCompiled() { $string = "Foo @lang(function_call('foo(blah)')) bar"; - $expected = "Foo getFromJson(function_call('foo(blah)'))); ?> bar"; + $expected = "Foo getFromJson(function_call('foo(blah)')); ?> bar"; $this->assertEquals($expected, $this->compiler->compileString($string)); } public function testLanguageAndChoicesAreCompiled() { - $this->assertEquals('getFromJson(\'foo\')); ?>', $this->compiler->compileString("@lang('foo')")); - $this->assertEquals('choice(\'foo\', 1)); ?>', $this->compiler->compileString("@choice('foo', 1)")); + $this->assertEquals('getFromJson(\'foo\'); ?>', $this->compiler->compileString("@lang('foo')")); + $this->assertEquals('choice(\'foo\', 1); ?>', $this->compiler->compileString("@choice('foo', 1)")); } }