mirror of
https://github.com/go-gitea/gitea.git
synced 2025-12-15 21:45:35 +08:00
Compare commits
3 Commits
87d1fe5345
...
0b095ef4ee
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0b095ef4ee | ||
|
|
ac8308b5cb | ||
|
|
eb2b6fc16c |
@ -125,12 +125,16 @@ func DetectEncoding(content []byte) (encoding string, _ error) {
|
|||||||
cnt := 0
|
cnt := 0
|
||||||
for end >= 0 && cnt < 4 {
|
for end >= 0 && cnt < 4 {
|
||||||
c := toValidate[end]
|
c := toValidate[end]
|
||||||
if c>>6 == 0b10 {
|
|
||||||
end--
|
|
||||||
}
|
|
||||||
if c>>5 == 0b110 || c>>4 == 0b1110 || c>>3 == 0b11110 {
|
if c>>5 == 0b110 || c>>4 == 0b1110 || c>>3 == 0b11110 {
|
||||||
|
// a leading byte
|
||||||
toValidate = toValidate[:end]
|
toValidate = toValidate[:end]
|
||||||
break
|
break
|
||||||
|
} else if c>>6 == 0b10 {
|
||||||
|
// a continuation byte
|
||||||
|
end--
|
||||||
|
} else {
|
||||||
|
// not an utf-8 byte
|
||||||
|
break
|
||||||
}
|
}
|
||||||
cnt++
|
cnt++
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,7 +4,6 @@
|
|||||||
package charset
|
package charset
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
@ -228,12 +227,21 @@ func TestToUTF8WithFallbackReader(t *testing.T) {
|
|||||||
|
|
||||||
content := strings.Repeat(block, 2)
|
content := strings.Repeat(block, 2)
|
||||||
for i := 1; i < len(content); i++ {
|
for i := 1; i < len(content); i++ {
|
||||||
encoding, _ := DetectEncoding([]byte(content[:i]))
|
encoding, err := DetectEncoding([]byte(content[:i]))
|
||||||
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, "UTF-8", encoding)
|
assert.Equal(t, "UTF-8", encoding)
|
||||||
|
|
||||||
ToUTF8WithFallbackReaderPrefetchSize = i
|
ToUTF8WithFallbackReaderPrefetchSize = i
|
||||||
rd := ToUTF8WithFallbackReader(bytes.NewReader([]byte(content)), ConvertOpts{})
|
rd := ToUTF8WithFallbackReader(strings.NewReader(content), ConvertOpts{})
|
||||||
r, _ := io.ReadAll(rd)
|
r, _ := io.ReadAll(rd)
|
||||||
assert.Equal(t, content, string(r))
|
assert.Equal(t, content, string(r))
|
||||||
}
|
}
|
||||||
|
for _, r := range runes {
|
||||||
|
content = "abc abc " + string(r) + string(r) + string(r)
|
||||||
|
for i := 0; i < len(content); i++ {
|
||||||
|
encoding, err := DetectEncoding([]byte(content[:i]))
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, "UTF-8", encoding)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,20 +2,10 @@
|
|||||||
import {SvgIcon} from '../svg.ts';
|
import {SvgIcon} from '../svg.ts';
|
||||||
import {isPlainClick} from '../utils/dom.ts';
|
import {isPlainClick} from '../utils/dom.ts';
|
||||||
import {shallowRef} from 'vue';
|
import {shallowRef} from 'vue';
|
||||||
import {type createViewFileTreeStore} from './ViewFileTreeStore.ts';
|
import type {createViewFileTreeStore, FileTreeItem} from './ViewFileTreeStore.ts';
|
||||||
|
|
||||||
export type Item = {
|
|
||||||
entryName: string;
|
|
||||||
entryMode: 'blob' | 'exec' | 'tree' | 'commit' | 'symlink' | 'unknown';
|
|
||||||
entryIcon: string;
|
|
||||||
entryIconOpen: string;
|
|
||||||
fullPath: string;
|
|
||||||
submoduleUrl?: string;
|
|
||||||
children?: Item[];
|
|
||||||
};
|
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
item: Item,
|
item: FileTreeItem,
|
||||||
store: ReturnType<typeof createViewFileTreeStore>
|
store: ReturnType<typeof createViewFileTreeStore>
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
|
|||||||
@ -3,11 +3,20 @@ import {GET} from '../modules/fetch.ts';
|
|||||||
import {pathEscapeSegments} from '../utils/url.ts';
|
import {pathEscapeSegments} from '../utils/url.ts';
|
||||||
import {createElementFromHTML} from '../utils/dom.ts';
|
import {createElementFromHTML} from '../utils/dom.ts';
|
||||||
import {html} from '../utils/html.ts';
|
import {html} from '../utils/html.ts';
|
||||||
import type {Item} from './ViewFileTreeItem.vue';
|
|
||||||
|
export type FileTreeItem = {
|
||||||
|
entryName: string;
|
||||||
|
entryMode: 'blob' | 'exec' | 'tree' | 'commit' | 'symlink' | 'unknown';
|
||||||
|
entryIcon: string;
|
||||||
|
entryIconOpen: string;
|
||||||
|
fullPath: string;
|
||||||
|
submoduleUrl?: string;
|
||||||
|
children?: Array<FileTreeItem>;
|
||||||
|
};
|
||||||
|
|
||||||
export function createViewFileTreeStore(props: {repoLink: string, treePath: string, currentRefNameSubURL: string}) {
|
export function createViewFileTreeStore(props: {repoLink: string, treePath: string, currentRefNameSubURL: string}) {
|
||||||
const store = reactive({
|
const store = reactive({
|
||||||
rootFiles: [] as Array<Item>,
|
rootFiles: [] as Array<FileTreeItem>,
|
||||||
selectedItem: props.treePath,
|
selectedItem: props.treePath,
|
||||||
|
|
||||||
async loadChildren(treePath: string, subPath: string = '') {
|
async loadChildren(treePath: string, subPath: string = '') {
|
||||||
|
|||||||
4
web_src/js/globals.d.ts
vendored
4
web_src/js/globals.d.ts
vendored
@ -12,8 +12,8 @@ declare module '*.vue' {
|
|||||||
import type {DefineComponent} from 'vue';
|
import type {DefineComponent} from 'vue';
|
||||||
const component: DefineComponent<unknown, unknown, any>;
|
const component: DefineComponent<unknown, unknown, any>;
|
||||||
export default component;
|
export default component;
|
||||||
// List of named exports from vue components, used to make `tsc` output clean.
|
// Here we declare all exports from vue files so `tsc` or `tsgo` can work for
|
||||||
// To actually lint .vue files, `vue-tsc` is used because `tsc` can not parse them.
|
// non-vue files. To lint .vue files, `vue-tsc` must be used.
|
||||||
export function initDashboardRepoList(): void;
|
export function initDashboardRepoList(): void;
|
||||||
export function initRepositoryActionView(): void;
|
export function initRepositoryActionView(): void;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user