use of java.util.regex.PatternSyntaxException in project Singularity by HubSpot.
the class MailTemplateHelpers method getLogErrorRegex.
private Optional<Pattern> getLogErrorRegex(final Optional<SingularityTask> task) {
Optional<String> maybeRegex;
SMTPConfiguration configuration = smtpConfiguration.get();
if (task.isPresent() && task.get().getTaskRequest().getRequest().getTaskLogErrorRegex().isPresent() && !task.get().getTaskRequest().getRequest().getTaskLogErrorRegex().get().equals("")) {
maybeRegex = task.get().getTaskRequest().getRequest().getTaskLogErrorRegex();
} else {
maybeRegex = configuration.getTaskLogErrorRegex();
}
if (!maybeRegex.isPresent()) {
LOG.trace("No task log error regex provided.");
return Optional.absent();
}
String regex = maybeRegex.get();
Boolean caseSensitive;
if (task.isPresent() && task.get().getTaskRequest().getRequest().getTaskLogErrorRegexCaseSensitive().isPresent()) {
caseSensitive = task.get().getTaskRequest().getRequest().getTaskLogErrorRegexCaseSensitive().get();
} else if (configuration.getTaskLogErrorRegexCaseSensitive().isPresent()) {
caseSensitive = configuration.getTaskLogErrorRegexCaseSensitive().get();
} else {
caseSensitive = true;
}
try {
if (caseSensitive) {
return Optional.of(Pattern.compile(regex));
} else {
return Optional.of(Pattern.compile(regex, Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE));
}
} catch (PatternSyntaxException e) {
LOG.error("Invalid task log error regex supplied: \"{}\". Received exception: {}", regex, e);
return Optional.absent();
}
}
use of java.util.regex.PatternSyntaxException in project nebula.widgets.nattable by eclipse.
the class SearchDialog method doFind0.
private void doFind0(final boolean isIncremental, final String text) {
BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() {
@Override
public void run() {
PositionCoordinate previous = new PositionCoordinate(SearchDialog.this.selections.peek().pos);
try {
final SearchCommand searchCommand = createSearchCommand(text, isIncremental);
final SearchEventListener searchEventListener = new SearchEventListener();
searchCommand.setSearchEventListener(searchEventListener);
SearchDialog.this.natTable.doCommand(searchCommand);
if (searchEventListener.pos == null) {
// Beep and show status if not found
// $NON-NLS-1$
SearchDialog.this.statusLabel.setText(Messages.getString("Search.textNotFound"));
getShell().getDisplay().beep();
} else {
SelectionItem selection = new SelectionItem(text, searchEventListener.pos);
SearchDialog.this.selections.push(selection);
if (!isIncremental) {
resetIncrementalSelections();
}
// Beep and show status if wrapped
if (previous != null && previous.columnPosition > -1) {
int columnDelta = selection.pos.columnPosition - previous.columnPosition;
int rowDelta = selection.pos.rowPosition - previous.rowPosition;
if (!SearchDialog.this.forwardValue) {
columnDelta = -columnDelta;
rowDelta = -rowDelta;
}
int primaryDelta = SearchDialog.this.columnFirstValue ? columnDelta : rowDelta;
int secondaryDelta = SearchDialog.this.columnFirstValue ? rowDelta : columnDelta;
if (primaryDelta < 0 || !isIncremental && primaryDelta == 0 && secondaryDelta <= 0) {
// $NON-NLS-1$
SearchDialog.this.statusLabel.setText(Messages.getString("Search.wrappedSearch"));
getShell().getDisplay().beep();
}
}
}
if (!isIncremental) {
updateFindHistory();
}
} catch (PatternSyntaxException e) {
SearchDialog.this.statusLabel.setText(e.getLocalizedMessage());
SearchDialog.this.statusLabel.setForeground(JFaceColors.getErrorText(SearchDialog.this.statusLabel.getDisplay()));
getShell().getDisplay().beep();
}
}
});
}
use of java.util.regex.PatternSyntaxException in project nebula.widgets.nattable by eclipse.
the class DefaultGlazedListsFilterStrategy method applyFilter.
/**
* Create GlazedLists matcher editors and apply them to facilitate
* filtering.
*/
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public void applyFilter(Map<Integer, Object> filterIndexToObjectMap) {
if (filterIndexToObjectMap.isEmpty()) {
// wait until all listeners had the chance to handle the clear event
try {
this.filterLock.writeLock().lock();
this.matcherEditor.getMatcherEditors().clear();
} finally {
this.filterLock.writeLock().unlock();
}
return;
}
try {
EventList<MatcherEditor<T>> matcherEditors = new BasicEventList<MatcherEditor<T>>();
for (Entry<Integer, Object> mapEntry : filterIndexToObjectMap.entrySet()) {
Integer columnIndex = mapEntry.getKey();
String filterText = getStringFromColumnObject(columnIndex, mapEntry.getValue());
String textDelimiter = this.configRegistry.getConfigAttribute(FilterRowConfigAttributes.TEXT_DELIMITER, DisplayMode.NORMAL, FilterRowDataLayer.FILTER_ROW_COLUMN_LABEL_PREFIX + columnIndex);
TextMatchingMode textMatchingMode = this.configRegistry.getConfigAttribute(FilterRowConfigAttributes.TEXT_MATCHING_MODE, DisplayMode.NORMAL, FilterRowDataLayer.FILTER_ROW_COLUMN_LABEL_PREFIX + columnIndex);
IDisplayConverter displayConverter = this.configRegistry.getConfigAttribute(FilterRowConfigAttributes.FILTER_DISPLAY_CONVERTER, DisplayMode.NORMAL, FilterRowDataLayer.FILTER_ROW_COLUMN_LABEL_PREFIX + columnIndex);
Comparator comparator = this.configRegistry.getConfigAttribute(FilterRowConfigAttributes.FILTER_COMPARATOR, DisplayMode.NORMAL, FilterRowDataLayer.FILTER_ROW_COLUMN_LABEL_PREFIX + columnIndex);
final Function<T, Object> columnValueProvider = getColumnValueProvider(columnIndex);
List<ParseResult> parseResults = FilterRowUtils.parse(filterText, textDelimiter, textMatchingMode);
EventList<MatcherEditor<T>> stringMatcherEditors = new BasicEventList<MatcherEditor<T>>();
for (ParseResult parseResult : parseResults) {
try {
MatchType matchOperation = parseResult.getMatchOperation();
if (matchOperation == MatchType.NONE) {
stringMatcherEditors.add(getTextMatcherEditor(columnIndex, textMatchingMode, displayConverter, parseResult.getValueToMatch()));
} else {
Object threshold = displayConverter.displayToCanonicalValue(parseResult.getValueToMatch());
matcherEditors.add(getThresholdMatcherEditor(columnIndex, threshold, comparator, columnValueProvider, matchOperation));
}
} catch (PatternSyntaxException e) {
// $NON-NLS-1$
LOG.warn("Error on applying a filter: " + e.getLocalizedMessage());
}
}
if (stringMatcherEditors.size() > 0) {
final CompositeMatcherEditor<T> stringCompositeMatcherEditor = new CompositeMatcherEditor<T>(stringMatcherEditors);
stringCompositeMatcherEditor.setMode(CompositeMatcherEditor.OR);
matcherEditors.add(stringCompositeMatcherEditor);
}
}
// wait until all listeners had the chance to handle the clear event
try {
this.filterLock.writeLock().lock();
// Remove the existing matchers that are removed from
// 'filterIndexToObjectMap'
final Iterator<MatcherEditor<T>> existingMatcherEditors = this.matcherEditor.getMatcherEditors().iterator();
while (existingMatcherEditors.hasNext()) {
final MatcherEditor<T> existingMatcherEditor = existingMatcherEditors.next();
if (!containsMatcherEditor(matcherEditors, existingMatcherEditor)) {
existingMatcherEditors.remove();
}
}
// 'filterIndexToObjectMap'
for (final MatcherEditor<T> matcherEditor : matcherEditors) {
if (!containsMatcherEditor(this.matcherEditor.getMatcherEditors(), matcherEditor)) {
this.matcherEditor.getMatcherEditors().add(matcherEditor);
}
}
} finally {
this.filterLock.writeLock().unlock();
}
} catch (Exception e) {
// $NON-NLS-1$
LOG.error("Error on applying a filter", e);
}
}
use of java.util.regex.PatternSyntaxException in project jsql-injection by ron190.
the class SuspendableGetRows method run.
@Override
public String run(Object... args) throws JSqlException {
String initialSQLQuery = (String) args[0];
String[] sourcePage = (String[]) args[1];
boolean isUsingLimit = (Boolean) args[2];
int numberToFind = (Integer) args[3];
AbstractElementDatabase searchName = (AbstractElementDatabase) args[4];
ThreadUtil.put(searchName, this);
String sqlQuery = initialSQLQuery.replaceAll("\\{limit\\}", MediatorModel.model().getVendor().instance().sqlLimit(0));
AbstractStrategy strategy;
// TODO Optionnal
if (MediatorModel.model().getStrategy() != null) {
strategy = MediatorModel.model().getStrategy().instance();
} else {
return "";
}
/*
* As we know the expected number of rows (numberToFind), then it stops injection if all rows are found,
* keep track of rows we have reached (limitSQLResult) and use these to skip entire rows,
* keep track of characters we have reached (startPosition) and use these to skip characters,
*/
StringBuilder slidingWindowAllRows = new StringBuilder();
String partOldRow = "";
StringBuilder slidingWindowCurrentRow = new StringBuilder();
int sqlLimit = 0;
int charPositionInCurrentRow = 1;
int infiniteLoop = 0;
while (true) {
if (this.isSuspended()) {
StoppedByUserSlidingException e = new StoppedByUserSlidingException();
e.setSlidingWindowAllRows(slidingWindowAllRows.toString());
e.setSlidingWindowCurrentRows(slidingWindowCurrentRow.toString());
throw e;
} else if (strategy == null) {
// Fix #1905 : NullPointerException on injectionStrategy.inject()
throw new InjectionFailureException("Undefined startegy");
}
sourcePage[0] = strategy.inject(sqlQuery, Integer.toString(charPositionInCurrentRow), this);
/**
* After ${LEAD} tag, gets characters between 1 and maxPerf
* performanceQuery() gets 65536 characters or less
* ${LEAD}blahblah1337 ] : end or limit+1
* ${LEAD}blahblah blah] : continue substr()
*/
// Parse all the data we have retrieved
Matcher regexAtLeastOneRow;
try {
regexAtLeastOneRow = Pattern.compile("(?s)" + LEAD + "(?i)(.{1," + strategy.getPerformanceLength() + "})").matcher(sourcePage[0]);
} catch (PatternSyntaxException e) {
// Fix #35382 : PatternSyntaxException null on SQLi(.{1,null})
throw new InjectionFailureException("Row parsing failed using capacity", e);
}
// TODO: prevent to find the last line directly: MODE + LEAD + .* + TRAIL_RGX
// It creates extra query which can be endless if not nullified
Matcher regexEndOfLine = Pattern.compile("(?s)" + LEAD + "(?i)" + TRAIL_RGX).matcher(sourcePage[0]);
if (regexEndOfLine.find() && isUsingLimit && !"".equals(slidingWindowAllRows.toString())) {
// Update the view only if there are value to find, and if it's not the root (empty tree)
if (numberToFind > 0 && searchName != null) {
Request request = new Request();
request.setMessage(Interaction.UPDATE_PROGRESS);
request.setParameters(searchName, numberToFind);
MediatorModel.model().sendToViews(request);
}
break;
}
/*
* Ending condition:
* One row could be very long, longer than the database can provide
* TODO Need verification
*/
if (!regexAtLeastOneRow.find() && isUsingLimit && !"".equals(slidingWindowAllRows.toString())) {
// Update the view only if there are value to find, and if it's not the root (empty tree)
if (numberToFind > 0 && searchName != null) {
Request request = new Request();
request.setMessage(Interaction.UPDATE_PROGRESS);
request.setParameters(searchName, numberToFind);
MediatorModel.model().sendToViews(request);
}
break;
}
// Fix #40947: OutOfMemoryError on append()
try {
if (partOldRow.equals(regexAtLeastOneRow.group(1))) {
infiniteLoop++;
if (infiniteLoop >= 20) {
SlidingException e = new LoopDetectedSlidingException();
e.setSlidingWindowAllRows(slidingWindowAllRows.toString());
e.setSlidingWindowCurrentRows(slidingWindowCurrentRow.toString());
throw e;
}
}
partOldRow = regexAtLeastOneRow.group(1);
slidingWindowCurrentRow.append(regexAtLeastOneRow.group(1));
Request request = new Request();
request.setMessage(Interaction.MESSAGE_CHUNK);
request.setParameters(Pattern.compile(MODE + TRAIL_RGX + ".*").matcher(regexAtLeastOneRow.group(1)).replaceAll("").replaceAll("\\n", "\\\\\\n").replaceAll("\\r", "\\\\\\r").replaceAll("\\t", "\\\\\\t"));
MediatorModel.model().sendToViews(request);
} catch (IllegalStateException | OutOfMemoryError e) {
// if it's not the root (empty tree)
if (searchName != null) {
Request request = new Request();
request.setMessage(Interaction.END_PROGRESS);
request.setParameters(searchName);
MediatorModel.model().sendToViews(request);
}
StringBuilder messageError = new StringBuilder("Fetching fails: no data to parse");
if (searchName != null) {
messageError.append(" for " + StringUtil.detectUtf8(searchName.toString()));
}
if (searchName instanceof Table && searchName.getChildCount() > 0) {
messageError.append(", if possible retry with one column selected only");
}
throw new InjectionFailureException(messageError.toString(), e);
}
/*
* Check how many rows we have collected from the beginning of that chunk
*/
regexAtLeastOneRow = Pattern.compile(MODE + "(" + ENCLOSE_VALUE_RGX + "([^\\x01-\\x09\\x0B-\\x0C\\x0E-\\x1F]*?)" + SEPARATOR_QTE_RGX + "([^\\x01-\\x09\\x0B-\\x0C\\x0E-\\x1F]*?)(\\x08)?" + ENCLOSE_VALUE_RGX + ")").matcher(slidingWindowCurrentRow);
int nbCompleteLine = 0;
while (regexAtLeastOneRow.find()) {
nbCompleteLine++;
}
/*
* Inform the view about the progression
*/
if (isUsingLimit && numberToFind > 0 && searchName != null) {
Request request = new Request();
request.setMessage(Interaction.UPDATE_PROGRESS);
request.setParameters(searchName, sqlLimit + nbCompleteLine);
MediatorModel.model().sendToViews(request);
}
/* Design Pattern: State? */
if (nbCompleteLine > 0 || slidingWindowCurrentRow.toString().matches("(?s).*" + TRAIL_RGX + ".*")) {
/*
* Remove everything after our result
* => hhxxxxxxxxjj00hhgghh...h |-> iLQSjunk
*/
String currentRow = slidingWindowCurrentRow.toString();
slidingWindowCurrentRow.setLength(0);
slidingWindowCurrentRow.append(Pattern.compile(MODE + TRAIL_RGX + ".*").matcher(currentRow).replaceAll(""));
slidingWindowAllRows.append(slidingWindowCurrentRow.toString());
if (isUsingLimit) {
/*
* Remove everything not properly attached to the last row:
* 1. very start of a new row: XXXXXhhg[ghh]$
* 2. very end of the last row: XXXXX[jj00]$
*/
String allRowsLimit = slidingWindowAllRows.toString();
slidingWindowAllRows.setLength(0);
slidingWindowAllRows.append(Pattern.compile(MODE + "(" + SEPARATOR_CELL_RGX + ENCLOSE_VALUE_RGX + "|" + SEPARATOR_QTE_RGX + "\\d*" + ")$").matcher(allRowsLimit).replaceAll(""));
String currentRowLimit = slidingWindowCurrentRow.toString();
slidingWindowCurrentRow.setLength(0);
slidingWindowCurrentRow.append(Pattern.compile(MODE + "(" + SEPARATOR_CELL_RGX + ENCLOSE_VALUE_RGX + "|" + SEPARATOR_QTE_RGX + "\\d*" + ")$").matcher(currentRowLimit).replaceAll(""));
/*
* Check either if there is more than 1 row and if there is less than 1 complete row
*/
regexAtLeastOneRow = Pattern.compile(MODE + "[^\\x01-\\x09\\x0B-\\x0C\\x0E-\\x1F]" + ENCLOSE_VALUE_RGX + SEPARATOR_CELL_RGX + ENCLOSE_VALUE_RGX + "[^\\x01-\\x09\\x0B-\\x0C\\x0E-\\x1F]+?$").matcher(slidingWindowCurrentRow);
Matcher regexRowIncomplete = Pattern.compile(MODE + ENCLOSE_VALUE_RGX + "[^\\x01-\\x03\\x05-\\x09\\x0B-\\x0C\\x0E-\\x1F]+?$").matcher(slidingWindowCurrentRow);
/*
* If there is more than 1 row, delete the last incomplete one in order to restart properly from it at the next loop,
* else if there is 1 row but incomplete, mark it as cut with the letter c
*/
if (regexAtLeastOneRow.find()) {
String allLine = slidingWindowAllRows.toString();
slidingWindowAllRows.setLength(0);
slidingWindowAllRows.append(Pattern.compile(MODE + ENCLOSE_VALUE_RGX + "[^\\x01-\\x09\\x0B-\\x0C\\x0E-\\x1F]+?$").matcher(allLine).replaceAll(""));
} else if (regexRowIncomplete.find()) {
slidingWindowAllRows.append(StringUtil.hexstr("05") + "1" + StringUtil.hexstr("0804"));
}
/*
* Check how many rows we have collected from the very beginning of the query,
* then skip every rows we have already found via LIMIT
*/
regexAtLeastOneRow = /*
* Regex \\x{08}? not supported on Kali
* => \\x08? seems ok though
*/
Pattern.compile(MODE + "(" + ENCLOSE_VALUE_RGX + "[^\\x01-\\x09\\x0B-\\x0C\\x0E-\\x1F]*?" + SEPARATOR_QTE_RGX + "[^\\x01-\\x09\\x0B-\\x0C\\x0E-\\x1F]*?\\x08?" + ENCLOSE_VALUE_RGX + ")").matcher(slidingWindowAllRows);
nbCompleteLine = 0;
while (regexAtLeastOneRow.find()) {
nbCompleteLine++;
}
sqlLimit = nbCompleteLine;
// Inform the view about the progression
if (numberToFind > 0 && searchName != null) {
Request request = new Request();
request.setMessage(Interaction.UPDATE_PROGRESS);
request.setParameters(searchName, sqlLimit);
MediatorModel.model().sendToViews(request);
}
/*
* Ending condition: every expected rows have been retrieved.
* Inform the view about the progression
*/
if (sqlLimit == numberToFind) {
if (numberToFind > 0 && searchName != null) {
Request request = new Request();
request.setMessage(Interaction.UPDATE_PROGRESS);
request.setParameters(searchName, numberToFind);
MediatorModel.model().sendToViews(request);
}
break;
}
/*
* Add the LIMIT statement to the next SQL query and reset variables.
* Put the character cursor to the beginning of the line, and reset the result of the current query
*/
sqlQuery = Pattern.compile(MODE + "\\{limit\\}").matcher(initialSQLQuery).replaceAll(MediatorModel.model().getVendor().instance().sqlLimit(sqlLimit));
slidingWindowCurrentRow.setLength(0);
} else {
// Inform the view about the progression
if (numberToFind > 0 && searchName != null) {
Request request = new Request();
request.setMessage(Interaction.UPDATE_PROGRESS);
request.setParameters(searchName, numberToFind);
MediatorModel.model().sendToViews(request);
}
break;
}
}
charPositionInCurrentRow = slidingWindowCurrentRow.length() + 1;
}
ThreadUtil.remove(searchName);
return slidingWindowAllRows.toString();
}
use of java.util.regex.PatternSyntaxException in project ballerina by ballerina-lang.
the class FindAllWithRegex method execute.
@Override
public void execute(Context context) {
String initialString = context.getStringArgument(0);
BStruct regexStruct = (BStruct) context.getRefArgument(0);
try {
Pattern pattern = validatePattern(regexStruct);
BStringArray stringArray = new BStringArray();
Matcher matcher = pattern.matcher(initialString);
int i = 0;
while (matcher.find()) {
stringArray.add(i++, matcher.group());
}
context.setReturnValues(stringArray);
} catch (PatternSyntaxException e) {
context.setReturnValues(BLangVMErrors.createError(context, 0, e.getMessage()));
}
}
Aggregations