2
0
Эх сурвалжийг харах

Fluent API: validate input parameters for Hyperlink, Section, and SectionLink methods

Marcin Ziąbek 3 долоо хоног өмнө
parent
commit
70e951e289

+ 9 - 0
Source/QuestPDF/Fluent/ElementExtensions.cs

@@ -285,6 +285,9 @@ namespace QuestPDF.Fluent
         /// <include file='../Resources/Documentation.xml' path='documentation/doc[@for="param.url"]/*' />
         public static IContainer Hyperlink(this IContainer element, string url)
         {
+            if (string.IsNullOrWhiteSpace(url))
+                throw new ArgumentException("The URL cannot be null or whitespace.", nameof(url));
+            
             return element.Element(new Hyperlink
             {
                 Url = url
@@ -310,6 +313,9 @@ namespace QuestPDF.Fluent
         /// <param name="sectionName">An internal text key representing the section. It should be unique and won't appear in the final document.</param>
         public static IContainer Section(this IContainer element, string sectionName)
         {
+            if (string.IsNullOrWhiteSpace(sectionName))
+                throw new ArgumentException("The section name cannot be null or whitespace.", nameof(sectionName));
+            
             return element
                 .DebugPointer(DebugPointerType.Section, sectionName)
                 .Element(new Section
@@ -332,6 +338,9 @@ namespace QuestPDF.Fluent
         /// <include file='../Resources/Documentation.xml' path='documentation/doc[@for="param.sectionName"]/*' />
         public static IContainer SectionLink(this IContainer element, string sectionName)
         {
+            if (string.IsNullOrWhiteSpace(sectionName))
+                throw new ArgumentException("The section name cannot be null or whitespace.", nameof(sectionName));
+            
             return element.Element(new SectionLink
             {
                 SectionName = sectionName

+ 4 - 5
Source/QuestPDF/Fluent/TextExtensions.cs

@@ -6,7 +6,6 @@ using QuestPDF.Elements;
 using QuestPDF.Elements.Text;
 using QuestPDF.Elements.Text.Items;
 using QuestPDF.Infrastructure;
-using static System.String;
 
 namespace QuestPDF.Fluent
 {
@@ -360,8 +359,8 @@ namespace QuestPDF.Fluent
         /// <include file='../Resources/Documentation.xml' path='documentation/doc[@for="text.returns.spanDescriptor"]/*' />
         public TextSpanDescriptor SectionLink(string? text, string sectionName)
         {
-            if (IsNullOrEmpty(sectionName))
-                throw new ArgumentException("Section name cannot be null or empty", nameof(sectionName));
+            if (string.IsNullOrWhiteSpace(sectionName))
+                throw new ArgumentException("Section name cannot be null or whitespace.", nameof(sectionName));
 
             if (text == null)
                 return new TextSpanDescriptor(new TextBlockSpan());
@@ -390,8 +389,8 @@ namespace QuestPDF.Fluent
         /// <include file='../Resources/Documentation.xml' path='documentation/doc[@for="text.returns.spanDescriptor"]/*' />
         public TextSpanDescriptor Hyperlink(string? text, string url)
         {
-            if (IsNullOrEmpty(url))
-                throw new ArgumentException("Url cannot be null or empty", nameof(url));
+            if (string.IsNullOrWhiteSpace(url))
+                throw new ArgumentException("Url cannot be null or whitespace.", nameof(url));
 
             if (text == null)
                 return new TextSpanDescriptor(new TextBlockSpan());