瀏覽代碼

Merge pull request #244 from viest/fix-243

fix: #243
viest 5 年之前
父節點
當前提交
98188f1c4f
共有 2 個文件被更改,包括 72 次插入18 次删除
  1. 23 18
      kernel/read.c
  2. 49 0
      tests/fix-243.phpt

+ 23 - 18
kernel/read.c

@@ -198,30 +198,35 @@ void data_to_custom_type(const char *string_value, const size_t string_value_len
     STRING:
 
     {
-        zend_long _long = 0; double _double = 0;
-
         if (!(type & READ_TYPE_STRING)) {
+            zend_long _long = 0; double _double = 0;
             is_numeric_string(string_value, string_value_length, &_long, &_double, 0);
-        }
 
-        if (Z_TYPE_P(zv_result_t) == IS_ARRAY) {
-            if (_double > 0) {
-                add_index_double(zv_result_t, zv_hashtable_index, _double);
-                return;
-            } else if (_long > 0) {
-                add_index_long(zv_result_t, zv_hashtable_index, _long);
-                return;
-            }
+            if (Z_TYPE_P(zv_result_t) == IS_ARRAY) {
+                if (_double > 0) {
+                    add_index_double(zv_result_t, zv_hashtable_index, _double);
+                    return;
+                }
 
-            add_index_stringl(zv_result_t, zv_hashtable_index, string_value, string_value_length);
-            return;
+                if (_long > 0) {
+                    add_index_long(zv_result_t, zv_hashtable_index, _long);
+                    return;
+                }
+            } else {
+                if (_double > 0) {
+                    ZVAL_DOUBLE(zv_result_t, _double);
+                    return;
+                }
+
+                if (_long > 0) {
+                    ZVAL_LONG(zv_result_t, _long);
+                    return;
+                }
+            }
         }
 
-        if (_double > 0) {
-            ZVAL_DOUBLE(zv_result_t, _double);
-            return;
-        } else if (_long > 0) {
-            ZVAL_LONG(zv_result_t, _long);
+        if (Z_TYPE_P(zv_result_t) == IS_ARRAY) {
+            add_index_stringl(zv_result_t, zv_hashtable_index, string_value, string_value_length);
             return;
         }
 

+ 49 - 0
tests/fix-243.phpt

@@ -0,0 +1,49 @@
+--TEST--
+Check for vtiful presence
+--SKIPIF--
+<?php
+require __DIR__ . '/include/skipif.inc';
+skip_disable_reader();
+?>
+--FILE--
+<?php
+$config = ['path' => './tests'];
+$excel  = new \Vtiful\Kernel\Excel($config);
+
+$filePath = $excel->fileName('tutorial.xlsx')
+    ->header(['NumberToString', 'Number'])
+    ->data([
+        ['01234567', '01234567']
+    ])
+    ->output();
+
+$data = $excel->openFile('tutorial.xlsx')
+    ->openSheet()
+    ->setType([
+        \Vtiful\Kernel\Excel::TYPE_STRING,
+    ])
+    ->getSheetData();
+
+var_dump($data);
+?>
+--CLEAN--
+<?php
+@unlink(__DIR__ . '/tutorial.xlsx');
+?>
+--EXPECT--
+array(2) {
+  [0]=>
+  array(2) {
+    [0]=>
+    string(14) "NumberToString"
+    [1]=>
+    string(6) "Number"
+  }
+  [1]=>
+  array(2) {
+    [0]=>
+    string(8) "01234567"
+    [1]=>
+    int(1234567)
+  }
+}