Limit print title fallback to masked Russian document names
This commit is contained in:
@@ -402,6 +402,17 @@ function Test-LooksLikeMojibakeQuestionMarks {
|
|||||||
return $Value -match '\?{2,}'
|
return $Value -match '\?{2,}'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Test-LooksLikeRussianTitleMaskedAsQuestionMarks {
|
||||||
|
param([AllowNull()][string]$Value)
|
||||||
|
if ([string]::IsNullOrWhiteSpace($Value)) { return $false }
|
||||||
|
|
||||||
|
$trimmed = $Value.Trim()
|
||||||
|
if ($trimmed -match '[A-Za-zА-Яа-я0-9]') { return $false }
|
||||||
|
|
||||||
|
# Typical broken Cyrillic print title shape: multiple words of question marks.
|
||||||
|
return $trimmed -match '^\?{3,}(\s+\?{3,})+$'
|
||||||
|
}
|
||||||
|
|
||||||
function Normalize-OwnerForMatch {
|
function Normalize-OwnerForMatch {
|
||||||
param([AllowNull()][string]$Value)
|
param([AllowNull()][string]$Value)
|
||||||
if ([string]::IsNullOrWhiteSpace($Value)) { return '' }
|
if ([string]::IsNullOrWhiteSpace($Value)) { return '' }
|
||||||
@@ -709,12 +720,12 @@ while ($true) {
|
|||||||
if ($script:SeenPrintJob.ContainsKey($jobId)) { continue }
|
if ($script:SeenPrintJob.ContainsKey($jobId)) { continue }
|
||||||
$script:SeenPrintJob[$jobId] = (Get-Date).ToUniversalTime()
|
$script:SeenPrintJob[$jobId] = (Get-Date).ToUniversalTime()
|
||||||
|
|
||||||
$printerName = [string]$job.Name
|
$printerName = Normalize-PrinterForMatch -Value ([string]$job.Name)
|
||||||
$documentName = [string]$job.Document
|
$documentName = [string]$job.Document
|
||||||
$owner = [string]$job.Owner
|
$owner = [string]$job.Owner
|
||||||
$documentNameOriginal = $documentName
|
$documentNameOriginal = $documentName
|
||||||
|
|
||||||
if (Test-LooksLikeMojibakeQuestionMarks -Value $documentName) {
|
if (Test-LooksLikeRussianTitleMaskedAsQuestionMarks -Value $documentName) {
|
||||||
$eventDocumentName = Get-BetterDocumentNameFromPrintServiceEvents -Owner $owner -PrinterName $printerName
|
$eventDocumentName = Get-BetterDocumentNameFromPrintServiceEvents -Owner $owner -PrinterName $printerName
|
||||||
if ($eventDocumentName) {
|
if ($eventDocumentName) {
|
||||||
$documentName = $eventDocumentName
|
$documentName = $eventDocumentName
|
||||||
|
|||||||
@@ -402,6 +402,17 @@ function Test-LooksLikeMojibakeQuestionMarks {
|
|||||||
return $Value -match '\?{2,}'
|
return $Value -match '\?{2,}'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Test-LooksLikeRussianTitleMaskedAsQuestionMarks {
|
||||||
|
param([AllowNull()][string]$Value)
|
||||||
|
if ([string]::IsNullOrWhiteSpace($Value)) { return $false }
|
||||||
|
|
||||||
|
$trimmed = $Value.Trim()
|
||||||
|
if ($trimmed -match '[A-Za-zА-Яа-я0-9]') { return $false }
|
||||||
|
|
||||||
|
# Typical broken Cyrillic print title shape: multiple words of question marks.
|
||||||
|
return $trimmed -match '^\?{3,}(\s+\?{3,})+$'
|
||||||
|
}
|
||||||
|
|
||||||
function Normalize-OwnerForMatch {
|
function Normalize-OwnerForMatch {
|
||||||
param([AllowNull()][string]$Value)
|
param([AllowNull()][string]$Value)
|
||||||
if ([string]::IsNullOrWhiteSpace($Value)) { return '' }
|
if ([string]::IsNullOrWhiteSpace($Value)) { return '' }
|
||||||
@@ -709,12 +720,12 @@ while ($true) {
|
|||||||
if ($script:SeenPrintJob.ContainsKey($jobId)) { continue }
|
if ($script:SeenPrintJob.ContainsKey($jobId)) { continue }
|
||||||
$script:SeenPrintJob[$jobId] = (Get-Date).ToUniversalTime()
|
$script:SeenPrintJob[$jobId] = (Get-Date).ToUniversalTime()
|
||||||
|
|
||||||
$printerName = [string]$job.Name
|
$printerName = Normalize-PrinterForMatch -Value ([string]$job.Name)
|
||||||
$documentName = [string]$job.Document
|
$documentName = [string]$job.Document
|
||||||
$owner = [string]$job.Owner
|
$owner = [string]$job.Owner
|
||||||
$documentNameOriginal = $documentName
|
$documentNameOriginal = $documentName
|
||||||
|
|
||||||
if (Test-LooksLikeMojibakeQuestionMarks -Value $documentName) {
|
if (Test-LooksLikeRussianTitleMaskedAsQuestionMarks -Value $documentName) {
|
||||||
$eventDocumentName = Get-BetterDocumentNameFromPrintServiceEvents -Owner $owner -PrinterName $printerName
|
$eventDocumentName = Get-BetterDocumentNameFromPrintServiceEvents -Owner $owner -PrinterName $printerName
|
||||||
if ($eventDocumentName) {
|
if ($eventDocumentName) {
|
||||||
$documentName = $eventDocumentName
|
$documentName = $eventDocumentName
|
||||||
|
|||||||
Reference in New Issue
Block a user