Skip to content

Commit 90a4de0

Browse files
joyeecheungtargos
authored andcommitted
src: do not format single string argument for THROW_ERR_*
If the macros are used as ERR_*(isolate, message) or THROW_ERR_*(isolate, message) with a single string argument, do run formatter on the message, and allow the caller to pass in a message directly with characters that would otherwise need escaping if used as format string unconditionally. PR-URL: #57126 Refs: https://github.com/fisker/prettier-issue-17139 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
1 parent d62299b commit 90a4de0

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/node_errors.h

+11-1
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,21 @@ void OOMErrorHandler(const char* location, const v8::OOMDetails& details);
115115
V(ERR_WORKER_INIT_FAILED, Error) \
116116
V(ERR_PROTO_ACCESS, Error)
117117

118+
// If the macros are used as ERR_*(isolate, message) or
119+
// THROW_ERR_*(isolate, message) with a single string argument, do run
120+
// formatter on the message, and allow the caller to pass in a message
121+
// directly with characters that would otherwise need escaping if used
122+
// as format string unconditionally.
118123
#define V(code, type) \
119124
template <typename... Args> \
120125
inline v8::Local<v8::Object> code( \
121126
v8::Isolate* isolate, const char* format, Args&&... args) { \
122-
std::string message = SPrintF(format, std::forward<Args>(args)...); \
127+
std::string message; \
128+
if (sizeof...(Args) == 0) { \
129+
message = format; \
130+
} else { \
131+
message = SPrintF(format, std::forward<Args>(args)...); \
132+
} \
123133
v8::Local<v8::String> js_code = FIXED_ONE_BYTE_STRING(isolate, #code); \
124134
v8::Local<v8::String> js_msg = \
125135
v8::String::NewFromUtf8(isolate, \

0 commit comments

Comments
 (0)