Skip to content
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

Fixed some Issues reported #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/vendor/
*.phar
composer.lock
phpunit.xml
phpunit.xml
*~
20 changes: 13 additions & 7 deletions src/KzykHys/CsvParser/Iterator/CsvIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,25 @@ public function current()
// loop over the columns
foreach ($tokens as $value) {
$value = preg_replace('/"(\r\n|\r|\n)*$/', '"', $value);


// check the first letter is 'enclosure' or not
if (substr($value, 0, 1) == $this->option['enclosure']) {
// check the last letter is 'enclosure'
if (substr($value, -1) == $this->option['enclosure']) {
$this->processEnclosedField($value, $this->option);
} else {
$this->processContinuousField($value, $this->option);
if ($this->continue) {
$this->processClosingField($value, $this->option);
}
else {
if (strlen($value) > 1 && (substr($value, -1) == $this->option['enclosure'])) {
$this->processEnclosedField($value, $this->option);
} else {
$this->processContinuousField($value, $this->option);
}
}

} else { // first letter is NOT 'enclosure'
// check the last letter is 'enclosure'
if(substr($value, -1) == $this->option['enclosure']) {
if (substr($value, -1) == $this->option['enclosure']) {
$this->processClosingField($value, $this->option);
} else {
$this->processField($value, $this->option);
Expand All @@ -118,7 +124,7 @@ public function current()
$this->revert = "";
$this->iterator->next();
}

return $this->result;
}

Expand Down Expand Up @@ -344,4 +350,4 @@ public function rewind()
$this->key = 0;
}

}
}
4 changes: 2 additions & 2 deletions test/KzykHys/CsvParser/CsvParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public function providePatterns()
$dir = __DIR__ . '/Resources/csv/';

$names = array(
'1-plain', '3-quote-escaping', '4-multiline', '5-multiline-2'
'1-plain', '3-quote-escaping', '4-multiline', '5-multiline-2', '7-multiline-3'
);

$patterns = array();
Expand Down Expand Up @@ -109,4 +109,4 @@ public function testMultibyteString()

}

}
}
1 change: 1 addition & 0 deletions test/KzykHys/CsvParser/Resources/csv/7-multiline-3.CR.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
",Column 1","Column 2","Column 3"
Expand Down
3 changes: 3 additions & 0 deletions test/KzykHys/CsvParser/Resources/csv/7-multiline-3.CRLF.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
",
Column 1","Column 2
","Column 3"
3 changes: 3 additions & 0 deletions test/KzykHys/CsvParser/Resources/csv/7-multiline-3.LF.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
",
Column 1","Column 2
","Column 3"
3 changes: 3 additions & 0 deletions test/KzykHys/CsvParser/Resources/csv/7-multiline-3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
[",\nColumn 1", "Column 2\n", "Column 3"]
]