-
Notifications
You must be signed in to change notification settings - Fork 125
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
parser error when DATE is empty #646
Comments
@JohnRDOrazio can you propose some code, and add a unit test, in a PR. It will be good to handle defective input data, rather than just have PHP "crash". |
I see better what's going on now. The I figure, for checking against validation errors, the most useful thing is a reference to the line number and perhaps a string representation of the line in question. It's not really useful to have a reference to the node object, unless it's possible to get the line number and a string representation of the line from the node? |
I'm seeing that vobject/lib/Parser/MimeDir.php Line 289 in caa7af8
vobject/lib/Parser/MimeDir.php Lines 296 to 298 in caa7af8
Perhaps the That way, even if the |
started a fix for this in PR #649 |
with this fix in place I'm able to gather the line number and string from the node passed in the errors, after calling <?php
class ICSErrorLevel {
const int REPAIRED = 1;
const int WARNING = 2;
const int FATAL = 3;
const ERROR_STRING = [
null,
'Repaired value',
'Warning',
'Fatal Error'
];
private string $errorString;
public function __construct( int $errorLevel ) {
$this->errorString = self::ERROR_STRING[ $errorLevel ];
}
public function __toString() {
return $this->errorString;
}
}
$response = new stdClass;
$response->messages = [];
$response->errors = [];
//after reading from a calendar file...
$errors = $vcalendar->validate();
if( count( $errors ) > 0 ) {
foreach( $errors as $error ) {
$errorLevel = new ICSErrorLevel( $error['level'] );
//$nodeType = get_class($error["node"]);
//$nodeValue = $error["node"]->getValue();
$response->errors[] = $errorLevel . ": " . $error['message'] . " at line {$error["node"]->lineIndex} ({$error["node"]->lineString})";// . "($nodeType)";
}
} else {
$response->messages[] = "No validation errors were found while validating data from the calendar resource";
}
header('Content-Type: application/json; charset=utf-8');
echo json_encode( $response, JSON_PRETTY_PRINT );
exit(0); I can now see in the output: "Fatal Error: The supplied value () is not a correct DATE-TIME at line 9277 (LAST-MODIFIED:)",
"Fatal Error: The supplied value () is not a correct DATE-TIME at line 9292 (CREATED:)",
"Fatal Error: The supplied value () is not a correct DATE-TIME at line 9294 (LAST-MODIFIED:)",
"Fatal Error: The supplied value () is not a correct DATE-TIME at line 9309 (CREATED:)", which is quite helpful for identifying the issues quickly and to the point. So instead of doing a |
I added a unit test to the PR which verifies that |
I was attempting to parse a defective ICS file, which happened to have empty
CREATED:
andLAST-MODIFIED:
fields:I wasn't getting parsing errors from the
validate()
call, instead I was getting PHP warnings about an uninitialized string offset 0 in theDateTimeParser::parse()
method, specifically from the line:The PHP warning made me realize that
$date
was empty, and in fact upon inspecting the ICS file I found the emptyCREATED:
andLAST-MODIFIED:
fields.Perhaps the parser should catch those situations in which the expected field has an empty value, and throw a catchable error?
vobject/lib/DateTimeParser.php
Lines 202 to 211 in caa7af8
The text was updated successfully, but these errors were encountered: