Skip to content

Commit ee54503

Browse files
committed
Redo over-zealous ncr encoding and check char limts better
1 parent f9efabc commit ee54503

4 files changed

Lines changed: 18 additions & 8 deletions

File tree

entity/rule.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,10 @@ public function set_title($title)
274274
// Enforce a string
275275
$title = (string) $title;
276276

277-
// Replace four-byte UTF-8 characters before storing in utf8mb3 columns.
278-
$title = utf8_encode_ucr($title);
277+
// MSSQL string literals cannot safely preserve every BMP character.
278+
$title = strpos($this->db->get_sql_layer(), 'mssql') === 0 ? utf8_encode_ncr($title) : utf8_encode_ucr($title);
279279

280-
// Limit both the displayed and stored title lengths to the column size.
280+
// Enforce the database column length after storage encoding.
281281
if (truncate_string($title, 200, 200) !== $title)
282282
{
283283
throw new \phpbb\boardrules\exception\unexpected_value(array('title', 'TOO_LONG'));

tests/entity/rule_entity_save_test.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,12 @@ public function test_four_byte_title_characters_are_encoded_and_other_unicode_is
8888
$this->db->sql_freeresult($result);
8989

9090
self::assertSame('emoji-title', $row['rule_anchor']);
91-
self::assertSame('Emoji 😀 中文 Кириллица title', $row['rule_title']);
91+
self::assertSame(
92+
strpos($this->db->get_sql_layer(), 'mssql') === 0
93+
? 'Emoji 😀 中文 Кириллица title'
94+
: 'Emoji 😀 中文 Кириллица title',
95+
$row['rule_title']
96+
);
9297

9398
$entity->load(1);
9499
self::assertSame('emoji-title', $entity->get_anchor());

tests/entity/rule_entity_title_test.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ public function title_test_data()
3535
str_repeat('a', 200),
3636
),
3737
array(
38-
str_repeat('К', 200),
39-
str_repeat('К', 200),
38+
str_repeat('😀', 22),
39+
str_repeat('😀', 22),
4040
),
4141
);
4242
}
@@ -76,10 +76,13 @@ public function title_fails_test_data()
7676
str_repeat('a', 201),
7777
),
7878

79-
// Escaped request value exceeds the stored column length.
79+
// Encoded request value exceeds the stored column length.
8080
array(
8181
str_repeat('a', 194) . '&&',
8282
),
83+
array(
84+
str_repeat('😀', 23),
85+
),
8386
);
8487
}
8588

tests/functional/admin_controller_test.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,9 @@ public function test_acp_create_rule($crawler)
167167
$stored_title = $this->db->sql_fetchfield('rule_title', false, $result);
168168
$this->db->sql_freeresult($result);
169169

170-
$expected_title = 'Test 😀 中文 Кириллица Rule';
170+
$expected_title = strpos($this->db->get_sql_layer(), 'mssql') === 0
171+
? 'Test 😀 中文 Кириллица Rule'
172+
: 'Test 😀 中文 Кириллица Rule';
171173
self::assertSame($expected_title, $stored_title);
172174
self::assertSame($rule_title, utf8_decode_ncr($stored_title));
173175
}

0 commit comments

Comments
 (0)