Skip to content

Commit

Permalink
analizators/1643
Browse files Browse the repository at this point in the history
  • Loading branch information
SuhorukovAnton committed Jan 21, 2022
1 parent 2029c34 commit 3d635a4
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

using System;
using System.Runtime.Serialization;
using System.Text;

#endregion

Expand Down Expand Up @@ -95,7 +96,8 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont
if (denyActions == null || denyActions.Length == 0) throw new ArgumentNullException(nameof(denyActions));
if (actions.Length != denySubjects.Length || actions.Length != denyActions.Length)
throw new ArgumentException();
var reasons = "";

var sb = new StringBuilder();
for (var i = 0; i < actions.Length; i++)
{
var action = actions[i];
Expand All @@ -109,8 +111,9 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont
reason = $"{action.Name}: access denied.";
if (i != actions.Length - 1)
reason += ", ";
reasons += reason;
sb.Append(reason);
}
var reasons = sb.ToString();
var sactions = "";
Array.ForEach(actions, action => { sactions += action.ToString() + ", "; });
var message = $"\"{(subject is IRole ? "role:" : "") + subject.Name}\" access denied \"{sactions}\". Cause: {reasons}.";
Expand Down
7 changes: 4 additions & 3 deletions common/ASC.Core.Common/Notify/Cron/CronExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1004,10 +1004,11 @@ protected virtual TreeSet GetSet(int type)
protected virtual ValueSet GetValue(int v, string s, int i)
{
var c = s[i];
var s1 = v.ToString(CultureInfo.InvariantCulture);
var sb = new StringBuilder();
sb.Append(v.ToString(CultureInfo.InvariantCulture));
while (c >= '0' && c <= '9')
{
s1 += c;
sb.Append(c);
i++;
if (i >= s.Length)
{
Expand All @@ -1024,7 +1025,7 @@ protected virtual ValueSet GetValue(int v, string s, int i)
{
val.Pos = i + 1;
}
val.TheValue = Convert.ToInt32(s1, CultureInfo.InvariantCulture);
val.TheValue = Convert.ToInt32(sb.ToString(), CultureInfo.InvariantCulture);
return val;
}

Expand Down
5 changes: 3 additions & 2 deletions common/ASC.Data.Backup.Core/Tasks/PortalTaskBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,16 +294,17 @@ private async Task InternalRunMysqlFile(Stream stream, string delimiter)

while ((commandText = await reader.ReadLineAsync()) != null)
{
var sb = new StringBuilder(commandText);
while (!commandText.EndsWith(delimiter))
{
var newline = await reader.ReadLineAsync();
if (newline == null)
{
break;
}
commandText += newline;
sb.Append(newline);
}

commandText = sb.ToString();
try
{

Expand Down
13 changes: 8 additions & 5 deletions common/ASC.Notify.Textile/JabberStyler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@


using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;

Expand All @@ -48,25 +49,27 @@ public class JabberStyler : IPatternStyler

public void ApplyFormating(NoticeMessage message)
{
var body = string.Empty;
var sb = new StringBuilder();
if (!string.IsNullOrEmpty(message.Subject))
{
body += VelocityArguments.Replace(message.Subject, ArgMatchReplace) + Environment.NewLine;
sb.AppendLine(VelocityArguments.Replace(message.Subject, ArgMatchReplace));
message.Subject = string.Empty;
}
if (string.IsNullOrEmpty(message.Body)) return;
var lines = message.Body.Split(new[] { Environment.NewLine, "\n" }, StringSplitOptions.None);

for (var i = 0; i < lines.Length - 1; i++)
{
ref var line = ref lines[i];
if (string.IsNullOrEmpty(line)) { body += Environment.NewLine; continue; }
if (string.IsNullOrEmpty(line)) { sb.AppendLine(); continue; }
line = VelocityArguments.Replace(line, ArgMatchReplace);
body += LinkReplacer.Replace(line, EvalLink) + Environment.NewLine;
sb.AppendLine(LinkReplacer.Replace(line, EvalLink));
}

ref var lastLine = ref lines[^1];
lastLine = VelocityArguments.Replace(lastLine, ArgMatchReplace);
body += LinkReplacer.Replace(lastLine, EvalLink);
sb.Append(LinkReplacer.Replace(lastLine, EvalLink));
var body = sb.ToString();
body = TextileReplacer.Replace(HttpUtility.HtmlDecode(body), ""); //Kill textile markup
body = BrReplacer.Replace(body, Environment.NewLine);
body = ClosedTagsReplacer.Replace(body, Environment.NewLine);
Expand Down
10 changes: 6 additions & 4 deletions common/ASC.Textile/Blocks/GlyphBlockModifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#endregion

#region Using Statements
using System.Text;
using System.Text.RegularExpressions;
#endregion

Expand Down Expand Up @@ -39,7 +40,7 @@ public override string ModifyLine(string line)
{ @"\b ?[([](C|c)[])]", "&#169;" } // copyright
};

var output = "";
var sb = new StringBuilder();

if (!Regex.IsMatch(line, "<.*>"))
{
Expand All @@ -48,13 +49,14 @@ public override string ModifyLine(string line)
{
line = Regex.Replace(line, glyphs[i, 0], glyphs[i, 1]);
}
output = line;
sb.Append(line);
}
else
{
var splits = Regex.Split(line, "(<.*?>)");
var offtags = "code|pre|notextile";
var codepre = false;

foreach (var split in splits)
{
var modifiedSplit = split;
Expand Down Expand Up @@ -82,11 +84,11 @@ public override string ModifyLine(string line)
//line = line.Replace("&amp;#", "&#");
}

output += modifiedSplit;
sb.Append(modifiedSplit);
}
}

return output;
return sb.ToString();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json;

using ASC.Common;
Expand Down Expand Up @@ -195,7 +196,8 @@ private List<FileEntry<TTo>> MoveOrCopyFolders<TTo>(IServiceScope scope, List<T>
var toFolderId = toFolder.ID;
var isToFolder = Equals(toFolderId, DaoFolderId);


var sb = new StringBuilder();
sb.Append(Result);
foreach (var folderId in folderIds)
{
CancellationToken.ThrowIfCancellationRequested();
Expand Down Expand Up @@ -243,7 +245,7 @@ private List<FileEntry<TTo>> MoveOrCopyFolders<TTo>(IServiceScope scope, List<T>

if (ProcessedFolder(folderId))
{
Result += string.Format("folder_{0}{1}", newFolder.ID, SPLIT_CHAR);
sb.Append($"folder_{newFolder.ID}{SPLIT_CHAR}");
}
}

Expand All @@ -263,7 +265,7 @@ private List<FileEntry<TTo>> MoveOrCopyFolders<TTo>(IServiceScope scope, List<T>
FolderDao.DeleteFolder(folder.ID);
if (ProcessedFolder(folderId))
{
Result += string.Format("folder_{0}{1}", newFolder.ID, SPLIT_CHAR);
sb.Append($"folder_{newFolder.ID}{SPLIT_CHAR}");
}
}
}
Expand All @@ -284,7 +286,7 @@ private List<FileEntry<TTo>> MoveOrCopyFolders<TTo>(IServiceScope scope, List<T>

if (ProcessedFolder(folderId))
{
Result += string.Format("folder_{0}{1}", newFolderId, SPLIT_CHAR);
sb.Append($"folder_{newFolderId}{SPLIT_CHAR}");
}
}
else if (!FilesSecurity.CanDelete(folder))
Expand Down Expand Up @@ -316,7 +318,7 @@ private List<FileEntry<TTo>> MoveOrCopyFolders<TTo>(IServiceScope scope, List<T>

if (ProcessedFolder(folderId))
{
Result += string.Format("folder_{0}{1}", newFolderId, SPLIT_CHAR);
sb.Append($"folder_{newFolderId}{SPLIT_CHAR}");
}
}
}
Expand Down Expand Up @@ -353,10 +355,11 @@ private List<FileEntry<TTo>> MoveOrCopyFolders<TTo>(IServiceScope scope, List<T>

if (ProcessedFolder(folderId))
{
Result += string.Format("folder_{0}{1}", newFolderId, SPLIT_CHAR);
sb.Append($"folder_{newFolderId}{SPLIT_CHAR}");
}
}
}
}
Result = sb.ToString();
}
catch (Exception ex)
{
Expand All @@ -382,7 +385,8 @@ private List<FileEntry<TTo>> MoveOrCopyFiles<TTo>(IServiceScope scope, List<T> f
var fileDao = scope.ServiceProvider.GetService<IFileDao<TTo>>();
var fileTracker = scope.ServiceProvider.GetService<FileTrackerHelper>();

var toFolderId = toFolder.ID;
var toFolderId = toFolder.ID;
var sb = new StringBuilder();
foreach (var fileId in fileIds)
{
CancellationToken.ThrowIfCancellationRequested();
Expand Down Expand Up @@ -432,7 +436,7 @@ private List<FileEntry<TTo>> MoveOrCopyFiles<TTo>(IServiceScope scope, List<T> f

if (ProcessedFile(fileId))
{
Result += string.Format("file_{0}{1}", newFile.ID, SPLIT_CHAR);
sb.Append($"file_{newFile.ID}{SPLIT_CHAR}");
}
}
catch
Expand Down Expand Up @@ -480,7 +484,7 @@ private List<FileEntry<TTo>> MoveOrCopyFiles<TTo>(IServiceScope scope, List<T> f

if (ProcessedFile(fileId))
{
Result += string.Format("file_{0}{1}", newFileId, SPLIT_CHAR);
sb.Append($"file_{newFileId}{SPLIT_CHAR}");
}
}
}
Expand Down Expand Up @@ -535,7 +539,7 @@ private List<FileEntry<TTo>> MoveOrCopyFiles<TTo>(IServiceScope scope, List<T> f
filesMessageService.Send(newFile, toFolder, _headers, MessageAction.FileCopiedWithOverwriting, newFile.Title, parentFolder.Title, toFolder.Title);
if (ProcessedFile(fileId))
{
Result += string.Format("file_{0}{1}", newFile.ID, SPLIT_CHAR);
sb.Append($"file_{newFile.ID}{SPLIT_CHAR}");
}
}
else
Expand All @@ -544,7 +548,7 @@ private List<FileEntry<TTo>> MoveOrCopyFiles<TTo>(IServiceScope scope, List<T> f
{
if (ProcessedFile(fileId))
{
Result += string.Format("file_{0}{1}", newFile.ID, SPLIT_CHAR);
sb.Append($"file_{newFile.ID}{SPLIT_CHAR}");
}
}
else
Expand All @@ -568,7 +572,7 @@ private List<FileEntry<TTo>> MoveOrCopyFiles<TTo>(IServiceScope scope, List<T> f

if (ProcessedFile(fileId))
{
Result += string.Format("file_{0}{1}", newFile.ID, SPLIT_CHAR);
sb.Append($"file_{newFile.ID}{SPLIT_CHAR}");
}
}
}
Expand All @@ -589,7 +593,7 @@ private List<FileEntry<TTo>> MoveOrCopyFiles<TTo>(IServiceScope scope, List<T> f
}
ProgressStep(fileId: FolderDao.CanCalculateSubitems(fileId) ? default : fileId);
}

Result = sb.ToString();
return needToMark;
}

Expand Down
6 changes: 3 additions & 3 deletions web/ASC.Web.Core/Users/UserManagerWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,12 @@ internal static string GeneratePassword(int minLength, int maxLength, string noi
{
var length = RandomNumberGenerator.GetInt32(minLength, maxLength + 1);

var pwd = string.Empty;
var sb = new StringBuilder();
while (length-- > 0)
{
pwd += noise[RandomNumberGenerator.GetInt32(noise.Length - 1)];
sb.Append(noise[RandomNumberGenerator.GetInt32(noise.Length - 1)]);
}
return pwd;
return sb.ToString();
}

internal static string GenerateErrorMessage(PasswordSettings passwordSettings)
Expand Down

0 comments on commit 3d635a4

Please sign in to comment.