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

fix Issue2303, invalid characters in datetime field #4584

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ArqamFarooqui110719
Copy link
Contributor

Fix invalid character in datetime field, issue #2303

@ArqamFarooqui110719
Copy link
Contributor Author

@ArqamFarooqui110719 maybe you could do a PR including a .test covering the cases:

 | expires                  |
 |--------------------------|
 | 2016-04-05T14:10:0x.00Z  |
 | 2016-04-05T14:10:00,00Z  |
 | 2016-04-05T14:10:00.h00Z |
 | 2016-04-05T14:10:00.0h0Z |
 | 2016-04-05T14:10:00.,00L |

I have tested above cases, and found that case-1 i.e. "2016-04-05T14:10:0x.00Z" was passing successfully (i.e. a WRONG behavior) because sscanf() function in src/lib/common/globals.cpp +626 file were not able to detect the invalid character.

I have fixed the code for that case, also include a .test file covering all cases that you mentioned in issue #2303.

// sscanf() function i.e. used next to this 'for' loop.
for (char c : ss)
{
if (std::isalpha(c) && c != 'T' && c != 'Z')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parse8601Time() has a strong C flavour, so I'd suggest not using C++ functions is possible. It seems a simpliar isalpha() function is available in ctype.h module. See example:

#include <stdio.h>
#include <ctype.h>

int main() {
    char ch = 'A';

    if (isalpha(ch)) {
        printf("%c is an alphabetic character.\n", ch);
    } else {
        printf("%c is not an alphabetic character.\n", ch);
    }

    return 0;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants