Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 4, 2025

When users URL encode datetime values before passing them to the OData client, they were incorrectly wrapped in single quotes, causing server type errors. This happened because the prepareValue() method in Grammar.php didn't recognize URL-encoded datetime strings as datetime values.

Problem

User code like this:

$filterEarliest = urlencode('2000-02-05T08:48:36+08:00');
$filterLatest = urlencode('2023-03-05T08:48:36+08:00');

$result = $odataClient->from('ProductSearch')
    ->where('UpdatedAt', '>=', $filterEarliest)
    ->where('UpdatedAt', '<=', $filterLatest)
    ->get();

Generated an invalid OData query:

$filter=UpdatedAt ge '2000-02-05T08%3A48%3A36%2B08%3A00' and UpdatedAt le '2023-03-05T08%3A48%3A36%2B08%3A00'

This caused the server error:

"A binary operator with incompatible types was detected. Found operand types 'Edm.DateTimeOffset' and 'Edm.String' for operator kind 'GreaterThanOrEqual'."

Solution

Enhanced the Grammar.php class with two new detection methods:

  • isUrlEncodedDateTime() - Detects URL-encoded ISO 8601 datetime patterns
  • isDateTime() - Detects regular ISO 8601 datetime patterns

Updated prepareValue() to handle both URL-encoded and regular datetime values without wrapping them in quotes.

After Fix

The same user code now generates the correct OData query:

$filter=UpdatedAt ge 2000-02-05T08%3A48%3A36%2B08%3A00 and UpdatedAt le 2023-03-05T08%3A48%3A36%2B08%3A00

Supported Formats

  • Basic: 2023-12-25T10:30:00
  • With timezone: 2023-12-25T10:30:00+05:00
  • UTC: 2023-12-25T10:30:00Z
  • With milliseconds: 2023-12-25T10:30:00.123+05:00
  • All above formats when URL-encoded

Backward Compatibility

✅ Fully maintained - all existing functionality works exactly as before. String values are still properly quoted, and regular datetime values continue to work without modification.

Fixes #126.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/guzzle/guzzle/zipball/b51ac707cfa420b7bfd4e4d5e510ba8008e822b4
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/CuQYKA /usr/bin/composer install (http block)
  • https://api.github.com/repos/guzzle/promises/zipball/481557b130ef3790cf82b713667b43030dc9c957
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/CuQYKA /usr/bin/composer install (http block)
  • https://api.github.com/repos/guzzle/psr7/zipball/21dc724a0583619cd1652f673303492272778051
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/CuQYKA /usr/bin/composer install (http block)
  • https://api.github.com/repos/php-fig/clock/zipball/e41a24703d4560fd0acb709162f73b8adfc3aa0d
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/rVA2IJ /usr/bin/composer install --no-dev (http block)
  • https://api.github.com/repos/php-fig/http-factory/zipball/2b4765fddfe3b508ac62f829e852b1501d3f6e8a
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/CuQYKA /usr/bin/composer install (http block)
  • https://api.github.com/repos/php-fig/http-message/zipball/402d35bcb92c70c026d1a6a9883f06b2ead23d71
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/CuQYKA /usr/bin/composer install (http block)
  • https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/CuQYKA /usr/bin/composer install (http block)
  • https://api.github.com/repos/symfony/deprecation-contracts/zipball/63afe740e99a13ba87ec199bb07bbdee937a5b62
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/CuQYKA /usr/bin/composer install (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/rVA2IJ /usr/bin/composer install --no-dev (http block)
  • https://api.github.com/repos/symfony/polyfill-mbstring/zipball/6d857f4d76bd4b343eac26d6b539585d2bc56493
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/rVA2IJ /usr/bin/composer install --no-dev (http block)
  • https://api.github.com/repos/symfony/polyfill-php83/zipball/17f6f9a6b1735c0f163024d959f700cfbc5155e5
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/rVA2IJ /usr/bin/composer install --no-dev (http block)
  • https://api.github.com/repos/symfony/polyfill-php85/zipball/d4e5fcd4ab3d998ab16c0db48e6cbb9a01993f91
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/rVA2IJ /usr/bin/composer install --no-dev (http block)
  • https://api.github.com/repos/symfony/translation-contracts/zipball/df210c7a2573f1913b2d17cc95f90f53a73d8f7d
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/rVA2IJ /usr/bin/composer install --no-dev (http block)
  • https://api.github.com/repos/symfony/translation/zipball/e0837b4cbcef63c754d89a4806575cada743a38d
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/rVA2IJ /usr/bin/composer install --no-dev (http block)
  • https://api.github.com/repos/voku/portable-ascii/zipball/b1d923f88091c6bf09699efcd7c8a1b1bfd7351d
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/rVA2IJ /usr/bin/composer install --no-dev (http block)

If you need me to access, download, or install something from one of these locations, you can either:


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copy link
Contributor Author

Copilot AI commented Sep 4, 2025

@anderly 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

Copilot AI changed the title [WIP] URL encoding? Fix URL encoding for datetime values in OData queries Sep 4, 2025
Copilot AI requested a review from anderly September 4, 2025 04:16
@anderly anderly marked this pull request as ready for review September 4, 2025 04:50
@anderly anderly merged commit f6bd68e into master Sep 4, 2025
18 checks passed
@anderly anderly deleted the copilot/fix-126 branch September 4, 2025 05:17
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.

URL encoding?

2 participants