-
Notifications
You must be signed in to change notification settings - Fork 8k
add test for bug #70700 (LOB read loop ends early for multibyte strings) #1569
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
412637c
add test for bug #70700
ashnazg 6d602c5
remove workaround demos
ashnazg 0c3ccac
remove comments about lengths that work
ashnazg 4df3d32
fix fwrite behavior; add comments on how read() acts on characters, w…
ashnazg e5db6f5
add CREDITS
ashnazg f1890c8
fix title
ashnazg dee5b91
clarify test intention
ashnazg abe83fd
add NLS_LANG to env
ashnazg 2bf59d9
fix length on first test
ashnazg e8ad69a
add dot delimiter to NLS_LANG
ashnazg 541407f
skip test if mbstring not enabled
ashnazg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,183 @@ | ||
| --TEST-- | ||
| Tests for LOBs with multibyte strings, reading them out in chunks | ||
| (Doc Bug #70700) | ||
| --CREDITS-- | ||
| Chuck Burgess | ||
| [email protected] | ||
| --SKIPIF-- | ||
| <?php | ||
| if (!extension_loaded('mbstring')) die('skip mbstring is not enabled'); | ||
| $target_dbs = array('oracledb' => true, 'timesten' => false); // test runs on these DBs | ||
| require(dirname(__FILE__).'/skipif.inc'); | ||
| ?> | ||
| --ENV-- | ||
| NLS_LANG=.AL32UTF8 | ||
| --FILE-- | ||
| <?php | ||
| require(dirname(__FILE__).'/connect.inc'); | ||
|
|
||
|
|
||
| $stmt = oci_parse($c, 'DROP TABLE oci8_bug70700'); | ||
| @oci_execute($stmt); | ||
| oci_free_statement($stmt); | ||
| $stmt = oci_parse($c, 'CREATE TABLE oci8_bug70700 (id NUMBER, data CLOB)'); | ||
| oci_execute($stmt); | ||
| oci_free_statement($stmt); | ||
|
|
||
|
|
||
| $id = null; | ||
| $insert = oci_parse($c, 'INSERT INTO oci8_bug70700 (id, data) VALUES (:id, :data)'); | ||
| oci_bind_by_name($insert, ':id', $id); | ||
| $select = oci_parse($c, "SELECT data FROM oci8_bug70700 WHERE id = :id"); | ||
| oci_bind_by_name($select, ':id', $id); | ||
|
|
||
|
|
||
| echo PHP_EOL, 'Test 1: j', PHP_EOL; | ||
| $string1 = 'abc' . str_repeat('j', 1000000) . 'xyz'; | ||
| $id = 1; | ||
| $desc = oci_new_descriptor($c, OCI_D_LOB); | ||
| oci_bind_by_name($insert, ':data', $desc, -1, OCI_B_CLOB); | ||
| $desc->writeTemporary($string1, OCI_TEMP_CLOB); | ||
| oci_execute($insert); | ||
| $desc->save($string1); | ||
| oci_commit($c); | ||
| $desc->close(); | ||
| oci_bind_by_name($select, ':id', $id); | ||
| oci_execute($select); | ||
| $row = oci_fetch_array($select, OCI_ASSOC); | ||
| $lob = $row['DATA']; | ||
| $fh = fopen('php://temp', 'rw'); | ||
| while (! $lob->eof()) { | ||
| $data = $lob->read(8192); // read($characters), not read($bytes) | ||
| fwrite($fh, $data, strlen($data)); // fwrite(a, b, $bytes) | ||
| } | ||
| $lob->free(); | ||
| rewind($fh); | ||
| $stream1a = stream_get_contents($fh); | ||
| fclose($fh); | ||
| $start1a = mb_substr($stream1a, 0, 10); | ||
| $ending1a = mb_substr($stream1a, -10); | ||
| echo 'size of string1 is ', strlen($string1), ' bytes, ', mb_strlen($string1), ' chars.', PHP_EOL; | ||
| echo 'size of stream1a is ', strlen($stream1a), ' bytes, ', mb_strlen($stream1a), ' chars.', PHP_EOL; | ||
| echo 'beg of stream1a is ', $start1a, PHP_EOL; | ||
| echo 'end of stream1a is ', $ending1a, PHP_EOL; | ||
|
|
||
|
|
||
| echo PHP_EOL, 'Test 2: £', PHP_EOL; | ||
| $string2 = 'abc' . str_repeat('£', 4094) . 'xyz'; | ||
| $id = 2; | ||
| $desc = oci_new_descriptor($c, OCI_D_LOB); | ||
| oci_bind_by_name($insert, ':data', $desc, -1, OCI_B_CLOB); | ||
| $desc->writeTemporary($string2, OCI_TEMP_CLOB); | ||
| oci_execute($insert); | ||
| $desc->save($string2); | ||
| oci_commit($c); | ||
| $desc->close(); | ||
| oci_bind_by_name($select, ':id', $id); | ||
| oci_execute($select); | ||
| $row = oci_fetch_array($select, OCI_ASSOC); | ||
| $lob = $row['DATA']; | ||
| $fh = fopen('php://temp', 'rw'); | ||
| while (! $lob->eof()) { | ||
| $data = $lob->read(8192); // read($characters), not read($bytes) | ||
| fwrite($fh, $data, strlen($data)); // fwrite(a, b, $bytes) | ||
| } | ||
| $lob->free(); | ||
| rewind($fh); | ||
| $stream2a = stream_get_contents($fh); | ||
| fclose($fh); | ||
| $start2a = mb_substr($stream2a, 0, 10); | ||
| $ending2a = mb_substr($stream2a, -10); | ||
| echo 'size of string2 is ', strlen($string2), ' bytes, ', mb_strlen($string2), ' chars.', PHP_EOL; | ||
| echo 'size of stream2a is ', strlen($stream2a), ' bytes, ', mb_strlen($stream2a), ' chars.', PHP_EOL; | ||
| echo 'beg of stream2a is ', $start2a, PHP_EOL; | ||
| echo 'end of stream2a is ', $ending2a, PHP_EOL; | ||
|
|
||
|
|
||
| echo PHP_EOL, 'Test 3: Җ', PHP_EOL; | ||
| $string3 = 'abc' . str_repeat('Җ', 4094) . 'xyz'; | ||
| $id = 3; | ||
| $desc = oci_new_descriptor($c, OCI_D_LOB); | ||
| oci_bind_by_name($insert, ':data', $desc, -1, OCI_B_CLOB); | ||
| $desc->writeTemporary($string3, OCI_TEMP_CLOB); | ||
| oci_execute($insert); | ||
| $desc->save($string3); | ||
| oci_commit($c); | ||
| $desc->close(); | ||
| oci_bind_by_name($select, ':id', $id); | ||
| oci_execute($select); | ||
| $row = oci_fetch_array($select, OCI_ASSOC); | ||
| $lob = $row['DATA']; | ||
| $fh = fopen('php://temp', 'rw'); | ||
| while (! $lob->eof()) { | ||
| $data = $lob->read(8192); // read($characters), not read($bytes) | ||
| fwrite($fh, $data, strlen($data)); // fwrite(a, b, $bytes) | ||
| } | ||
| $lob->free(); | ||
| rewind($fh); | ||
| $stream3a = stream_get_contents($fh); | ||
| fclose($fh); | ||
| $start3a = mb_substr($stream3a, 0, 10); | ||
| $ending3a = mb_substr($stream3a, -10); | ||
| echo 'size of string3 is ', strlen($string3), ' bytes, ', mb_strlen($string3), ' chars.', PHP_EOL; | ||
| echo 'size of stream3a is ', strlen($stream3a), ' bytes, ', mb_strlen($stream3a), ' chars.', PHP_EOL; | ||
| echo 'beg of stream3a is ', $start3a, PHP_EOL; | ||
| echo 'end of stream3a is ', $ending3a, PHP_EOL; | ||
|
|
||
|
|
||
| echo PHP_EOL, 'Test 4: の', PHP_EOL; | ||
| $string4 = 'abc' . str_repeat('の', 2729) . 'xyz'; | ||
| $id = 4; | ||
| $desc = oci_new_descriptor($c, OCI_D_LOB); | ||
| oci_bind_by_name($insert, ':data', $desc, -1, OCI_B_CLOB); | ||
| $desc->writeTemporary($string4, OCI_TEMP_CLOB); | ||
| oci_execute($insert); | ||
| $desc->save($string4); | ||
| oci_commit($c); | ||
| $desc->close(); | ||
| oci_bind_by_name($select, ':id', $id); | ||
| oci_execute($select); | ||
| $row = oci_fetch_array($select, OCI_ASSOC); | ||
| $lob = $row['DATA']; | ||
| $fh = fopen('php://temp', 'rw'); | ||
| while (! $lob->eof()) { | ||
| $data = $lob->read(8192); // read($characters), not read($bytes) | ||
| fwrite($fh, $data, strlen($data)); // fwrite(a, b, $bytes) | ||
| } | ||
| $lob->free(); | ||
| rewind($fh); | ||
| $stream4a = stream_get_contents($fh); | ||
| fclose($fh); | ||
| $start4a = mb_substr($stream4a, 0, 10); | ||
| $ending4a = mb_substr($stream4a, -10); | ||
| echo 'size of string4 is ', strlen($string4), ' bytes, ', mb_strlen($string4), ' chars.', PHP_EOL; | ||
| echo 'size of stream4a is ', strlen($stream4a), ' bytes, ', mb_strlen($stream4a), ' chars.', PHP_EOL; | ||
| echo 'beg of stream4a is ', $start4a, PHP_EOL; | ||
| echo 'end of stream4a is ', $ending4a, PHP_EOL; | ||
|
|
||
| --EXPECTF-- | ||
|
|
||
| Test 1: j | ||
| size of string1 is 1000006 bytes, 1000006 chars. | ||
| size of stream1a is 1000006 bytes, 1000006 chars. | ||
| beg of stream1a is abcjjjjjjj | ||
| end of stream1a is jjjjjjjxyz | ||
|
|
||
| Test 2: £ | ||
| size of string2 is 8194 bytes, 4100 chars. | ||
| size of stream2a is 8194 bytes, 4100 chars. | ||
| beg of stream2a is abc£££££££ | ||
| end of stream2a is £££££££xyz | ||
|
|
||
| Test 3: Җ | ||
| size of string3 is 8194 bytes, 4100 chars. | ||
| size of stream3a is 8194 bytes, 4100 chars. | ||
| beg of stream3a is abcҖҖҖҖҖҖҖ | ||
| end of stream3a is ҖҖҖҖҖҖҖxyz | ||
|
|
||
| Test 4: の | ||
| size of string4 is 8193 bytes, 2735 chars. | ||
| size of stream4a is 8193 bytes, 2735 chars. | ||
| beg of stream4a is abcののののののの | ||
| end of stream4a is のののののののxyz | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add the following check here:
if (!extension_loaded('mbstring')) die('skip mbstring is not enabled');
After adding this, we're good to go.