Skip to content

Commit 77e89c3

Browse files
committed
fix(Core): ensure all custom uploader functions are registered
ShareX Custom Uploader Syntax Parser only populated the registry when given a file. This is a very bad bug that broke URL shorteners and URL sharing services (no file!) Now, the behaavior is more consistent and quarantined in the registry itself.
1 parent 2629df9 commit 77e89c3

4 files changed

Lines changed: 26 additions & 30 deletions

File tree

SnapX.Core/Upload/Custom/CustomUploaderFunctionRegistry.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,25 @@ internal static class CustomUploaderFunctionRegistry
88

99
internal static IReadOnlyList<CustomUploaderFunction> Functions => _functions;
1010

11-
internal static void Register(CustomUploaderFunction function)
11+
static CustomUploaderFunctionRegistry()
12+
{
13+
// Must manually do this shit wtf
14+
r(new CustomUploaderFunctionBase64());
15+
r(new CustomUploaderFunctionFileName());
16+
r(new CustomUploaderFunctionHeader());
17+
r(new CustomUploaderFunctionInput());
18+
r(new CustomUploaderFunctionInputBox());
19+
r(new CustomUploaderFunctionJson());
20+
r(new CustomUploaderFunctionOutputBox());
21+
r(new CustomUploaderFunctionRandom());
22+
r(new CustomUploaderFunctionRegex());
23+
r(new CustomUploaderFunctionResponse());
24+
r(new CustomUploaderFunctionResponseURL());
25+
r(new CustomUploaderFunctionSelect());
26+
r(new CustomUploaderFunctionXml());
27+
}
28+
29+
internal static void r(CustomUploaderFunction function)
1230
{
1331
_functions.Add(function);
1432
}

SnapX.Core/Upload/Custom/CustomUploaderItem.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ protected void OnPropertyChanged(string prop) =>
4141
public bool ShouldSerializeName() =>
4242
!string.IsNullOrEmpty(Name) && Name != URLHelpers.GetHostName(RequestURL);
4343

44-
[JsonConverter(typeof(JsonStringEnumConverter))]
44+
[JsonConverter(typeof(JsonStringEnumConverter<CustomUploaderDestinationType>))]
4545
[DefaultValue(CustomUploaderDestinationType.None)]
4646
public CustomUploaderDestinationType DestinationType
4747
{
@@ -94,7 +94,7 @@ public string? RequestURL
9494

9595
public bool ShouldSerializeHeaders() => Headers is { Count: > 0 };
9696

97-
[JsonConverter(typeof(JsonStringEnumConverter))]
97+
[JsonConverter(typeof(JsonStringEnumConverter<CustomUploaderBody>))]
9898
[DefaultValue(CustomUploaderBody.None)]
9999
public CustomUploaderBody Body { get; set; } = CustomUploaderBody.None;
100100

@@ -120,7 +120,7 @@ public bool ShouldSerializeData() =>
120120
(Body == CustomUploaderBody.JSON || Body == CustomUploaderBody.XML)
121121
&& !string.IsNullOrEmpty(Data);
122122

123-
[JsonConverter(typeof(JsonStringEnumConverter))]
123+
[JsonConverter(typeof(JsonStringEnumConverter<ResponseType>))]
124124
// TEMP: For backward compatibility
125125
public ResponseType ResponseType { private get; set; }
126126

@@ -260,11 +260,7 @@ public string GetContentType()
260260
return result;
261261
}
262262

263-
[UnconditionalSuppressMessage(
264-
"Trimming",
265-
"IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code",
266-
Justification = "<Pending>"
267-
)]
263+
268264
private string? EncodeBodyData(string? input)
269265
{
270266
if (!string.IsNullOrEmpty(input))

SnapX.Core/Upload/Custom/ShareXCustomUploaderSyntaxParser.cs

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ namespace SnapX.Core.Upload.Custom;
1212

1313
public class ShareXCustomUploaderSyntaxParser : ShareXSyntaxParser
1414
{
15-
private static IEnumerable<CustomUploaderFunction> Functions =>
16-
CustomUploaderFunctionRegistry.Functions;
1715

1816

1917
public string? FileName { get; set; }
@@ -23,26 +21,9 @@ public class ShareXCustomUploaderSyntaxParser : ShareXSyntaxParser
2321
public bool UseNameParser { get; set; }
2422
public NameParserType NameParserType { get; set; } = NameParserType.Text;
2523

26-
private void r(CustomUploaderFunction func)
27-
{
28-
CustomUploaderFunctionRegistry.Register(func);
29-
}
24+
3025
public ShareXCustomUploaderSyntaxParser()
3126
{
32-
// Must manually do this shit wtf
33-
r(new CustomUploaderFunctionBase64());
34-
r(new CustomUploaderFunctionFileName());
35-
r(new CustomUploaderFunctionHeader());
36-
r(new CustomUploaderFunctionInput());
37-
r(new CustomUploaderFunctionInputBox());
38-
r(new CustomUploaderFunctionJson());
39-
r(new CustomUploaderFunctionOutputBox());
40-
r(new CustomUploaderFunctionRandom());
41-
r(new CustomUploaderFunctionRegex());
42-
r(new CustomUploaderFunctionResponse());
43-
r(new CustomUploaderFunctionResponseURL());
44-
r(new CustomUploaderFunctionSelect());
45-
r(new CustomUploaderFunctionXml());
4627
}
4728

4829
public ShareXCustomUploaderSyntaxParser(CustomUploaderInput input)
@@ -71,7 +52,7 @@ public ShareXCustomUploaderSyntaxParser(CustomUploaderInput input)
7152
throw new Exception("Function name cannot be empty.");
7253
}
7354

74-
foreach (CustomUploaderFunction function in Functions)
55+
foreach (CustomUploaderFunction function in CustomUploaderFunctionRegistry.Functions)
7556
{
7657
if (!function.Name.Equals(functionName, StringComparison.OrdinalIgnoreCase) &&
7758
(function.Aliases == null ||

SnapX.Core/Upload/UploaderFactory.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ static UploaderFactory()
116116
Register(new OneTimeSecretTextUploaderService());
117117
Register(new Paste2TextUploaderService());
118118
Register(new Paste_eeTextUploaderService());
119+
Register(new PastieTextUploaderService());
119120
Register(new PastebinTextUploaderService());
120121
}
121122
}

0 commit comments

Comments
 (0)