Skip to content

Commit

Permalink
fix: handle case insensitivity
Browse files Browse the repository at this point in the history
  • Loading branch information
tale committed Feb 17, 2022
1 parent 8fc20ce commit 2737e50
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
25 changes: 23 additions & 2 deletions src/base.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,36 @@
export class CaseCopyMap extends Map<string, string> {
set(key: string, value: string): this {
super.set(`case_copying${key.toLowerCase()}`, key)
return super.set(key, value)
}

get(key: string): string | undefined {
if (super.has(key)) return super.get(key)

// Handle case insensitivity
const actualKey = super.get(`case_copying${key.toLowerCase()}`)
if (actualKey) return super.get(actualKey)
}


public get size() : number {
return super.size / 2
}

}

export class APTBase {
/**
* Raw-accessible key-value map of the APT format
*/
protected raw: Map<string, string>
protected raw: CaseCopyMap

/**
* Base constructor.
* This should never be used.
*/
constructor() {
this.raw = new Map()
this.raw = new CaseCopyMap()
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { CaseCopyMap } from './base'

export * from './control'
export * from './packages'
export * from './release'
Expand All @@ -11,7 +13,7 @@ export function parseKV(data: string) {
const cleanedData = data.replaceAll(/\r\n|\r|\n/g, '\n').replaceAll(/\0/g, '').normalize().trim()
const lineChunks = cleanedData.split('\n') // We know it will always be \n because of our cleanup

const fields = new Map<string, string>()
const fields = new CaseCopyMap()
let previousKey = ''

for (const line of lineChunks) {
Expand Down

0 comments on commit 2737e50

Please sign in to comment.