Skip to content

Commit eb84204

Browse files
joyeecheungmarco-ippolito
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 Backport-PR-URL: #59504 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> Refs: #52697
1 parent c1e7fa2 commit eb84204

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/node_errors.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,21 @@ void OOMErrorHandler(const char* location, const v8::OOMDetails& details);
105105
V(ERR_WORKER_INIT_FAILED, Error) \
106106
V(ERR_PROTO_ACCESS, Error)
107107

108+
// If the macros are used as ERR_*(isolate, message) or
109+
// THROW_ERR_*(isolate, message) with a single string argument, do run
110+
// formatter on the message, and allow the caller to pass in a message
111+
// directly with characters that would otherwise need escaping if used
112+
// as format string unconditionally.
108113
#define V(code, type) \
109114
template <typename... Args> \
110115
inline v8::Local<v8::Object> code( \
111116
v8::Isolate* isolate, const char* format, Args&&... args) { \
112-
std::string message = SPrintF(format, std::forward<Args>(args)...); \
117+
std::string message; \
118+
if (sizeof...(Args) == 0) { \
119+
message = format; \
120+
} else { \
121+
message = SPrintF(format, std::forward<Args>(args)...); \
122+
} \
113123
v8::Local<v8::String> js_code = OneByteString(isolate, #code); \
114124
v8::Local<v8::String> js_msg = \
115125
v8::String::NewFromUtf8(isolate, \

0 commit comments

Comments
 (0)