Skip to content
This repository has been archived by the owner on Dec 1, 2022. It is now read-only.

Commit

Permalink
add gflags to switch octal escape char support (#1079)
Browse files Browse the repository at this point in the history
  • Loading branch information
czpmango committed Jun 30, 2021
1 parent e664ee9 commit 8b3abc8
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 8 deletions.
3 changes: 2 additions & 1 deletion resources/gflags.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"system_memory_high_watermark_ratio",
"session_idle_timeout_secs",
"session_reclaim_interval_secs",
"max_allowed_connections"
"max_allowed_connections",
"disable_octal_escape_char"
],
"NESTED": [
"rocksdb_db_options",
Expand Down
27 changes: 21 additions & 6 deletions src/parser/scanner.lex
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "parser/GQLParser.h"
#include "parser/GraphScanner.h"
#include "GraphParser.hpp"
#include "service/GraphFlags.h"

#define YY_USER_ACTION \
yylloc->step(); \
Expand Down Expand Up @@ -380,21 +381,35 @@ IP_OCTET ([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])
sbufPos_ += yyleng;
}
<DQ_STR,SQ_STR>\\{OCT}{1,3} {
makeSpaceForString(1);
uint32_t val = 0;
sscanf(yytext + 1, "%o", &val);
if (val > 0xFF) {
if (FLAGS_disable_octal_escape_char) {
makeSpaceForString(yyleng);
::strncpy(sbuf() + sbufPos_, yytext, yyleng);
sbufPos_ += yyleng;
} else {
makeSpaceForString(1);
uint32_t val = 0;
sscanf(yytext + 1, "%o", &val);
if (val > 0xFF) {
yyterminate();
}
sbuf()[sbufPos_++] = val;
}
}
<DQ_STR,SQ_STR>\\{DEC}+ {
if (FLAGS_disable_octal_escape_char) {
makeSpaceForString(yyleng);
::strncpy(sbuf() + sbufPos_, yytext, yyleng);
sbufPos_ += yyleng;
} else {
yyterminate();
}
sbuf()[sbufPos_++] = val;
}
<DQ_STR,SQ_STR>\\[uUxX]{HEX}{4} {
auto encoded = folly::codePointToUtf8(std::strtoul(yytext+2, nullptr, 16));
makeSpaceForString(encoded.size());
::strncpy(sbuf() + sbufPos_, encoded.data(), encoded.size());
sbufPos_ += encoded.size();
}
<DQ_STR,SQ_STR>\\{DEC}+ { yyterminate(); }
<DQ_STR,SQ_STR>\\n {
makeSpaceForString(1);
sbuf()[sbufPos_++] = '\n';
Expand Down
3 changes: 3 additions & 0 deletions src/service/GraphFlags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,6 @@ DEFINE_uint32(ft_request_retry_times, 3, "Retry times if fulltext request failed
DEFINE_bool(accept_partial_success, false, "Whether to accept partial success, default false");

DEFINE_double(system_memory_high_watermark_ratio, 0.8, "high watermark ratio of system memory");

DEFINE_bool(disable_octal_escape_char, false, "Octal escape character will be disabled"
" in next version to ensure compatibility with cypher.");
1 change: 1 addition & 0 deletions src/service/GraphFlags.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ DECLARE_string(local_ip);
DECLARE_string(pid_file);
DECLARE_bool(local_config);
DECLARE_bool(accept_partial_success);
DECLARE_bool(disable_octal_escape_char);

DECLARE_bool(redirect_stdout);
DECLARE_string(stdout_log_file);
Expand Down
3 changes: 2 additions & 1 deletion tests/admin/test_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ def test_configs(self):
['GRAPH', 'system_memory_high_watermark_ratio', 'float', 'MUTABLE', 0.95],
['GRAPH', 'session_idle_timeout_secs', 'int', 'MUTABLE', 0],
['GRAPH', 'session_reclaim_interval_secs', 'int', 'MUTABLE', 10],
['GRAPH', 'max_allowed_connections', 'int', 'MUTABLE', 9223372036854775807]
['GRAPH', 'max_allowed_connections', 'int', 'MUTABLE', 9223372036854775807],
['GRAPH', 'disable_octal_escape_char', 'bool', 'MUTABLE', False],
]
self.check_out_of_order_result(resp, expected_result)

Expand Down

0 comments on commit 8b3abc8

Please sign in to comment.