Skip to content

Commit 731a887

Browse files
committed
Fixed bug #373 : Double quote usage fix removing too many double quotes
1 parent 0e34b55 commit 731a887

File tree

5 files changed

+32
-2
lines changed

5 files changed

+32
-2
lines changed

CodeSniffer/Standards/Squiz/Sniffs/Strings/DoubleQuoteUsageSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
122122

123123
if ($fix === true) {
124124
$phpcsFile->fixer->beginChangeset();
125-
$innerContent = trim($workingString, '"');
125+
$innerContent = substr($workingString, 1, -1);
126126
$innerContent = str_replace('\"', '"', $innerContent);
127127
$phpcsFile->fixer->replaceToken($stackPtr, "'$innerContent'");
128128
while ($lastStringToken !== $stackPtr) {

CodeSniffer/Standards/Squiz/Tests/Strings/DoubleQuoteUsageUnitTest.inc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ $string = "Hello
2222
there";
2323
$string = 'Hello
2424
there';
25-
?>
25+
26+
echo "window.location = \"".$url."\";\n";
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
$string = "Hello\tThere";
3+
$string = "Hello There\r\n";
4+
$string = 'Hello There';
5+
$string = "Hello $there";
6+
$string = 'Hello'."$there '".'hi';
7+
$string = "My name is 'Greg'";
8+
$string = 'Hello'.' There'."\n";
9+
$string = "Hello There\f";
10+
$string = "Hello There\b";
11+
$string = "Hello\vThere";
12+
$string = "\x0";
13+
$string = 'Hello '.$there.' Greg';
14+
$string = "<div class='$class'>";
15+
$string = "Value: $var[test]";
16+
$string = "\0";
17+
18+
$x = "bar = '$z',
19+
baz = '" . $a . "'...$x";
20+
21+
$string = 'Hello
22+
there';
23+
$string = 'Hello
24+
there';
25+
26+
echo 'window.location = "'.$url."\";\n";

CodeSniffer/Standards/Squiz/Tests/Strings/DoubleQuoteUsageUnitTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public function getErrorList()
5252
18 => 1,
5353
19 => 1,
5454
21 => 1,
55+
26 => 1,
5556
);
5657

5758
}//end getErrorList()

package.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
6262
- Fixed bug #371 : Shorthand binary cast causes tokenizer errors
6363
-- New token T_BINARY_CAST added for the b"string" cast format (the 'b' is the T_BINARY_CAST token)
6464
- Fixed bug #372 : phpcbf parse problem, wrong brace placement for inline IF
65+
- Fixed bug #373 : Double quote usage fix removing too many double quotes
6566
- Fixed bug #20196 : 1.5.2 breaks scope_closer position
6667
</notes>
6768
<contents>
@@ -2066,6 +2067,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
20662067
<tasks:replace from="@package_version@" to="version" type="package-info" />
20672068
</file>
20682069
<file baseinstalldir="PHP" name="DoubleQuoteUsageUnitTest.inc" role="test" />
2070+
<file baseinstalldir="PHP" name="DoubleQuoteUsageUnitTest.inc.fixed" role="test" />
20692071
<file baseinstalldir="PHP" name="DoubleQuoteUsageUnitTest.php" role="test">
20702072
<tasks:replace from="@package_version@" to="version" type="package-info" />
20712073
</file>

0 commit comments

Comments
 (0)