Skip to content

Commit d0564da

Browse files
Merge pull request #93 from wp-cli/placeholder-character-colorize
Use a more impossible placeholder pattern in `Colors::colorize()`
2 parents c6f72ea + 99aefde commit d0564da

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

lib/cli/Colors.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,13 @@ static public function colorize($string, $colored = null) {
127127
return $return;
128128
}
129129

130-
$string = str_replace('%%', '% ', $string);
130+
$string = str_replace('%%', '%¾', $string);
131131

132132
foreach (self::getColors() as $key => $value) {
133133
$string = str_replace($key, self::color($value), $string);
134134
}
135135

136-
$string = str_replace('% ', '%', $string);
136+
$string = str_replace('%¾', '%', $string);
137137
self::cacheString($passed, $string, $colored);
138138

139139
return $string;

tests/test-table-ascii.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,35 @@ public function testTableWithPercentCharacters() {
146146
| % at start | at end % | in % middle |
147147
+------------+----------+-------------+
148148

149+
OUT;
150+
$this->assertInOutEquals(array($headers, $rows), $output);
151+
}
152+
153+
/**
154+
* Test that a % is appropriately padded in the table
155+
*/
156+
public function testTablePaddingWithPercentCharacters() {
157+
$headers = array( 'ID', 'post_title', 'post_name' );
158+
$rows = array(
159+
array(
160+
3,
161+
'10%',
162+
''
163+
),
164+
array(
165+
1,
166+
'Hello world!',
167+
'hello-world'
168+
),
169+
);
170+
$output = <<<'OUT'
171+
+----+--------------+-------------+
172+
| ID | post_title | post_name |
173+
+----+--------------+-------------+
174+
| 3 | 10% | |
175+
| 1 | Hello world! | hello-world |
176+
+----+--------------+-------------+
177+
149178
OUT;
150179
$this->assertInOutEquals(array($headers, $rows), $output);
151180
}

0 commit comments

Comments
 (0)