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

PHP Extension - Field mask element may not have upper-case letter #20041

Open
FabioBatSilva opened this issue Jan 20, 2025 · 0 comments
Open
Labels
untriaged auto added to all issues by default when created.

Comments

@FabioBatSilva
Copy link

FabioBatSilva commented Jan 20, 2025

The PHP C extension implementation of Google\Protobuf\FieldMask has some validations that are not present in the native PHP implementation.

C Extension Validations:

if (ch >= 'A' && ch <= 'Z') {
jsonenc_err(e, "Field mask element may not have upper-case letter.");
} else if (ch == '_') {
if (ptr == end - 1 || *(ptr + 1) < 'a' || *(ptr + 1) > 'z') {
jsonenc_err(e, "Underscore must be followed by a lowercase letter.");
}
ch = *++ptr - 32;
}

jsondec_err(d, "field mask may not contain '_'");


What version of protobuf and what language are you using?
Version: main
Language: php
OS: Linux

What did you do?

<?php

require_once (dirname(__DIR__) . '/vendor/autoload.php');
require_once (__DIR__ . '/test_util.php');

use Google\Protobuf\FieldMask;

$m1 = new FieldMask();
$m2 = new FieldMask();

$m1->setPaths(['phoneNumber', 'email_address']);

$m2->mergeFromJsonString($m1->serializeToJsonString());

var_dump($m2->getPaths());
var_dump($m2->serializeToJsonString());
# Compile the extension 
./php/tests/compile_extension.sh

# Run script
php -d display_errors=on -dextension=../ext/google/protobuf/modules/protobuf.so field_mask_test.php

What did you expect to see

object(Google\Protobuf\Internal\RepeatedField)#640 (2) {
  [0]=>
  string(12) "phone_number"
  [1]=>
  string(13) "email_address"
}
string(26) ""phoneNumber,emailAddress""

Important

Not entirely sure if this behavior is correct.
This is the output I get in the PHP implementation
But the JSON serialization string(26) ""phoneNumber,emailAddress"" seems weird to me.

What did you see instead?

PHP Fatal error:  Uncaught Exception: Error occurred during JSON serialization: Field mask element may not have upper-case letter. 
@FabioBatSilva FabioBatSilva added the untriaged auto added to all issues by default when created. label Jan 20, 2025
@FabioBatSilva FabioBatSilva changed the title PHP Extension - Inconsistent Google\Protobuf\FieldMask behavior PHP Extension - Field mask element may not have upper-case letter Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
untriaged auto added to all issues by default when created.
Projects
None yet
Development

No branches or pull requests

1 participant