Skip to content

Commit acf50dc

Browse files
committed
Fix #962: Analyze() on an empty string should not throw an exception
1 parent 19ec2bd commit acf50dc

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

src/Nest/ElasticClient-Analyze.cs

-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ public IAnalyzeResponse Analyze(Func<AnalyzeDescriptor, AnalyzeDescriptor> analy
1616
IRequest<AnalyzeRequestParameters> request = d;
1717
var text = request.RequestParameters.GetQueryStringValue<string>("text");
1818
request.RequestParameters.RemoveQueryString("text");
19-
text.ThrowIfNullOrEmpty("No text specified to analyze");
2019
return this.RawDispatch.IndicesAnalyzeDispatch<AnalyzeResponse>(p, text);
2120
}
2221
);
@@ -32,7 +31,6 @@ public IAnalyzeResponse Analyze(IAnalyzeRequest analyzeRequest)
3231
IRequest<AnalyzeRequestParameters> request = d;
3332
var text = request.RequestParameters.GetQueryStringValue<string>("text");
3433
request.RequestParameters.RemoveQueryString("text");
35-
text.ThrowIfNullOrEmpty("No text specified to analyze");
3634
return this.RawDispatch.IndicesAnalyzeDispatch<AnalyzeResponse>(p, text);
3735
}
3836
);
@@ -48,7 +46,6 @@ public Task<IAnalyzeResponse> AnalyzeAsync(Func<AnalyzeDescriptor, AnalyzeDescri
4846
IRequest<AnalyzeRequestParameters> request = d;
4947
var text = request.RequestParameters.GetQueryStringValue<string>("text");
5048
request.RequestParameters.RemoveQueryString("text");
51-
text.ThrowIfNullOrEmpty("No text specified to analyze");
5249
return this.RawDispatch.IndicesAnalyzeDispatchAsync<AnalyzeResponse>(p, text);
5350
}
5451
);
@@ -64,7 +61,6 @@ public Task<IAnalyzeResponse> AnalyzeAsync(IAnalyzeRequest analyzeRequest)
6461
IRequest<AnalyzeRequestParameters> request = d;
6562
var text = request.RequestParameters.GetQueryStringValue<string>("text");
6663
request.RequestParameters.RemoveQueryString("text");
67-
text.ThrowIfNullOrEmpty("No text specified to analyze");
6864
return this.RawDispatch.IndicesAnalyzeDispatchAsync<AnalyzeResponse>(p, text);
6965
}
7066
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using NUnit.Framework;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using FluentAssertions;
8+
9+
namespace Nest.Tests.Integration.Core.Analyze
10+
{
11+
[TestFixture]
12+
public class AnalyzeTests : IntegrationTests
13+
{
14+
[Test]
15+
public void AnalyzeTest()
16+
{
17+
var request = new AnalyzeRequest("text to analyze");
18+
var result = this.Client.Analyze(request);
19+
result.IsValid.Should().BeTrue();
20+
}
21+
22+
[Test]
23+
public void AnalyzeEmptyStringDoesNotThrow()
24+
{
25+
var request = new AnalyzeRequest(string.Empty);
26+
var result = this.Client.Analyze(request);
27+
result.IsValid.Should().BeFalse();
28+
}
29+
}
30+
}

src/Tests/Nest.Tests.Integration/Nest.Tests.Integration.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
<Compile Include="Connection\Failover\SniffTests.cs" />
106106
<Compile Include="Connection\HttpClient\HttpClientTests.cs" />
107107
<Compile Include="Connection\Thrift\ThiftBugReportTests.cs" />
108+
<Compile Include="Core\Analyze\AnalyzeTests.cs" />
108109
<Compile Include="Core\Bulk\BulkTests.cs" />
109110
<Compile Include="Core\Bulk\BulkUpdateTests.cs" />
110111
<Compile Include="Core\CountTests.cs" />

0 commit comments

Comments
 (0)